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 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 void Reset(); | 1724 void Reset(); |
1726 | 1725 |
1727 void ResetStats() { wasted_bytes_ = 0; } | 1726 void ResetStats() { wasted_bytes_ = 0; } |
1728 | 1727 |
1729 // Return the number of bytes available on the free list. | 1728 // Return the number of bytes available on the free list. |
1730 intptr_t Available() { | 1729 intptr_t Available() { |
1731 return small_list_.available() + medium_list_.available() + | 1730 return small_list_.available() + medium_list_.available() + |
1732 large_list_.available() + huge_list_.available(); | 1731 large_list_.available() + huge_list_.available(); |
1733 } | 1732 } |
1734 | 1733 |
1735 // The method tries to find a {FreeSpace} node of at least {size_in_bytes} | |
1736 // size in the free list category exactly matching the size. If no suitable | |
1737 // node could be found, the method falls back to retrieving a {FreeSpace} | |
1738 // from the large or huge free list category. | |
1739 // | |
1740 // Can be used concurrently. | |
1741 MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t hint_size_in_bytes); | |
1742 | |
1743 bool IsEmpty() { | 1734 bool IsEmpty() { |
1744 return small_list_.IsEmpty() && medium_list_.IsEmpty() && | 1735 return small_list_.IsEmpty() && medium_list_.IsEmpty() && |
1745 large_list_.IsEmpty() && huge_list_.IsEmpty(); | 1736 large_list_.IsEmpty() && huge_list_.IsEmpty(); |
1746 } | 1737 } |
1747 | 1738 |
1748 // Used after booting the VM. | 1739 // Used after booting the VM. |
1749 void RepairLists(Heap* heap); | 1740 void RepairLists(Heap* heap); |
1750 | 1741 |
1751 intptr_t EvictFreeListItems(Page* p); | 1742 intptr_t EvictFreeListItems(Page* p); |
1752 bool ContainsPageFreeListItems(Page* p); | 1743 bool ContainsPageFreeListItems(Page* p); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 | 1835 |
1845 Object* object_; | 1836 Object* object_; |
1846 }; | 1837 }; |
1847 | 1838 |
1848 | 1839 |
1849 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); | 1840 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); |
1850 | 1841 |
1851 | 1842 |
1852 class PagedSpace : public Space { | 1843 class PagedSpace : public Space { |
1853 public: | 1844 public: |
1854 static const intptr_t kCompactionMemoryWanted = 500 * KB; | |
1855 | |
1856 // Creates a space with an id. | 1845 // Creates a space with an id. |
1857 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); | 1846 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); |
1858 | 1847 |
1859 virtual ~PagedSpace() { TearDown(); } | 1848 virtual ~PagedSpace() { TearDown(); } |
1860 | 1849 |
1861 // Set up the space using the given address range of virtual memory (from | 1850 // Set up the space using the given address range of virtual memory (from |
1862 // the memory allocator's initial chunk) if possible. If the block of | 1851 // the memory allocator's initial chunk) if possible. If the block of |
1863 // addresses is not big enough to contain a single page-aligned page, a | 1852 // addresses is not big enough to contain a single page-aligned page, a |
1864 // fresh chunk will be allocated. | 1853 // fresh chunk will be allocated. |
1865 bool SetUp(); | 1854 bool SetUp(); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 void EvictEvacuationCandidatesFromLinearAllocationArea(); | 2036 void EvictEvacuationCandidatesFromLinearAllocationArea(); |
2048 | 2037 |
2049 bool CanExpand(size_t size); | 2038 bool CanExpand(size_t size); |
2050 | 2039 |
2051 // Returns the number of total pages in this space. | 2040 // Returns the number of total pages in this space. |
2052 int CountTotalPages(); | 2041 int CountTotalPages(); |
2053 | 2042 |
2054 // Return size of allocatable area on a page in this space. | 2043 // Return size of allocatable area on a page in this space. |
2055 inline int AreaSize() { return area_size_; } | 2044 inline int AreaSize() { return area_size_; } |
2056 | 2045 |
2057 virtual bool is_local() { return false; } | |
2058 | |
2059 // Merges {other} into the current space. Note that this modifies {other}, | 2046 // Merges {other} into the current space. Note that this modifies {other}, |
2060 // e.g., removes its bump pointer area and resets statistics. | 2047 // e.g., removes its bump pointer area and resets statistics. |
2061 void MergeCompactionSpace(CompactionSpace* other); | 2048 void MergeCompactionSpace(CompactionSpace* other); |
2062 | 2049 |
2063 void DivideUponCompactionSpaces(CompactionSpaceCollection** other, int num, | 2050 void MoveOverFreeMemory(PagedSpace* other); |
2064 intptr_t limit = kCompactionMemoryWanted); | |
2065 | 2051 |
2066 // Refills the free list from the corresponding free list filled by the | 2052 virtual bool is_local() { return false; } |
2067 // sweeper. | |
2068 virtual void RefillFreeList(); | |
2069 | 2053 |
2070 protected: | 2054 protected: |
2071 void AddMemory(Address start, intptr_t size); | |
2072 | |
2073 FreeSpace* TryRemoveMemory(intptr_t size_in_bytes); | |
2074 | |
2075 void MoveOverFreeMemory(PagedSpace* other); | |
2076 | |
2077 // PagedSpaces that should be included in snapshots have different, i.e., | 2055 // PagedSpaces that should be included in snapshots have different, i.e., |
2078 // smaller, initial pages. | 2056 // smaller, initial pages. |
2079 virtual bool snapshotable() { return true; } | 2057 virtual bool snapshotable() { return true; } |
2080 | 2058 |
2081 FreeList* free_list() { return &free_list_; } | 2059 FreeList* free_list() { return &free_list_; } |
2082 | 2060 |
2083 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2061 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2084 | 2062 |
2085 // Cleans up the space, frees all pages in this space except those belonging | 2063 // Cleans up the space, frees all pages in this space except those belonging |
2086 // to the initial chunk, uncommits addresses in the initial chunk. | 2064 // to the initial chunk, uncommits addresses in the initial chunk. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 // The sweeper threads iterate over the list of pointer and data space pages | 2105 // The sweeper threads iterate over the list of pointer and data space pages |
2128 // and sweep these pages concurrently. They will stop sweeping after the | 2106 // and sweep these pages concurrently. They will stop sweeping after the |
2129 // end_of_unswept_pages_ page. | 2107 // end_of_unswept_pages_ page. |
2130 Page* end_of_unswept_pages_; | 2108 Page* end_of_unswept_pages_; |
2131 | 2109 |
2132 // Mutex guarding any concurrent access to the space. | 2110 // Mutex guarding any concurrent access to the space. |
2133 base::Mutex space_mutex_; | 2111 base::Mutex space_mutex_; |
2134 | 2112 |
2135 friend class MarkCompactCollector; | 2113 friend class MarkCompactCollector; |
2136 friend class PageIterator; | 2114 friend class PageIterator; |
2137 | |
2138 // Used in cctest. | |
2139 friend class HeapTester; | |
2140 }; | 2115 }; |
2141 | 2116 |
2142 | 2117 |
2143 class NumberAndSizeInfo BASE_EMBEDDED { | 2118 class NumberAndSizeInfo BASE_EMBEDDED { |
2144 public: | 2119 public: |
2145 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 2120 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
2146 | 2121 |
2147 int number() const { return number_; } | 2122 int number() const { return number_; } |
2148 void increment_number(int num) { number_ += num; } | 2123 void increment_number(int num) { number_ += num; } |
2149 | 2124 |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 public: | 2782 public: |
2808 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2783 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
2809 : PagedSpace(heap, id, executable) {} | 2784 : PagedSpace(heap, id, executable) {} |
2810 | 2785 |
2811 // Adds external memory starting at {start} of {size_in_bytes} to the space. | 2786 // Adds external memory starting at {start} of {size_in_bytes} to the space. |
2812 void AddExternalMemory(Address start, int size_in_bytes) { | 2787 void AddExternalMemory(Address start, int size_in_bytes) { |
2813 IncreaseCapacity(size_in_bytes); | 2788 IncreaseCapacity(size_in_bytes); |
2814 Free(start, size_in_bytes); | 2789 Free(start, size_in_bytes); |
2815 } | 2790 } |
2816 | 2791 |
2817 virtual bool is_local() override { return true; } | 2792 virtual bool is_local() { return true; } |
2818 | |
2819 virtual void RefillFreeList() override; | |
2820 | 2793 |
2821 protected: | 2794 protected: |
2822 // The space is temporary and not included in any snapshots. | 2795 // The space is temporary and not included in any snapshots. |
2823 virtual bool snapshotable() override { return false; } | 2796 virtual bool snapshotable() { return false; } |
2824 }; | 2797 }; |
2825 | 2798 |
2826 | 2799 |
2827 // A collection of |CompactionSpace|s used by a single compaction task. | 2800 // A collection of |CompactionSpace|s used by a single compaction task. |
2828 class CompactionSpaceCollection : public Malloced { | 2801 class CompactionSpaceCollection : public Malloced { |
2829 public: | 2802 public: |
2830 explicit CompactionSpaceCollection(Heap* heap) | 2803 explicit CompactionSpaceCollection(Heap* heap) |
2831 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), | 2804 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), |
2832 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} | 2805 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} |
2833 | 2806 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3039 count = 0; | 3012 count = 0; |
3040 } | 3013 } |
3041 // Must be small, since an iteration is used for lookup. | 3014 // Must be small, since an iteration is used for lookup. |
3042 static const int kMaxComments = 64; | 3015 static const int kMaxComments = 64; |
3043 }; | 3016 }; |
3044 #endif | 3017 #endif |
3045 } // namespace internal | 3018 } // namespace internal |
3046 } // namespace v8 | 3019 } // namespace v8 |
3047 | 3020 |
3048 #endif // V8_HEAP_SPACES_H_ | 3021 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |