Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/heap/spaces.h

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

Powered by Google App Engine
This is Rietveld 408576698