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

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

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