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

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

Issue 1382003002: [heap] Divide available memory upon compaction tasks (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@counters
Patch Set: Addressed first round of comments 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
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 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 appropriate free list category. If no suitable node could be
1732 // found, the method falls back to retrieving the largest possible {FreeSpace}
1733 // node in the free list. Upon returning nullptr the free list is observed as
1734 // empty.
1735 //
1736 // Can be used concurrently.
1737 MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t hint_size_in_bytes);
1738
1729 bool IsEmpty() { 1739 bool IsEmpty() {
1730 return small_list_.IsEmpty() && medium_list_.IsEmpty() && 1740 return small_list_.IsEmpty() && medium_list_.IsEmpty() &&
1731 large_list_.IsEmpty() && huge_list_.IsEmpty(); 1741 large_list_.IsEmpty() && huge_list_.IsEmpty();
1732 } 1742 }
1733 1743
1734 #ifdef DEBUG 1744 #ifdef DEBUG
1735 void Zap(); 1745 void Zap();
1736 intptr_t SumFreeLists(); 1746 intptr_t SumFreeLists();
1737 bool IsVeryLong(); 1747 bool IsVeryLong();
1738 #endif 1748 #endif
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 return &large_list_; 1783 return &large_list_;
1774 case kHuge: 1784 case kHuge:
1775 return &huge_list_; 1785 return &huge_list_;
1776 default: 1786 default:
1777 UNREACHABLE(); 1787 UNREACHABLE();
1778 } 1788 }
1779 UNREACHABLE(); 1789 UNREACHABLE();
1780 return nullptr; 1790 return nullptr;
1781 } 1791 }
1782 1792
1783
1784 PagedSpace* owner_; 1793 PagedSpace* owner_;
1785 Heap* heap_; 1794 Heap* heap_;
1786 base::Mutex mutex_; 1795 base::Mutex mutex_;
1787 intptr_t wasted_bytes_; 1796 intptr_t wasted_bytes_;
1788 FreeListCategory small_list_; 1797 FreeListCategory small_list_;
1789 FreeListCategory medium_list_; 1798 FreeListCategory medium_list_;
1790 FreeListCategory large_list_; 1799 FreeListCategory large_list_;
1791 FreeListCategory huge_list_; 1800 FreeListCategory huge_list_;
1792 1801
1793 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); 1802 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 void EvictEvacuationCandidatesFromFreeLists(); 2042 void EvictEvacuationCandidatesFromFreeLists();
2034 2043
2035 bool CanExpand(size_t size); 2044 bool CanExpand(size_t size);
2036 2045
2037 // Returns the number of total pages in this space. 2046 // Returns the number of total pages in this space.
2038 int CountTotalPages(); 2047 int CountTotalPages();
2039 2048
2040 // Return size of allocatable area on a page in this space. 2049 // Return size of allocatable area on a page in this space.
2041 inline int AreaSize() { return area_size_; } 2050 inline int AreaSize() { return area_size_; }
2042 2051
2052 virtual bool is_local() { return false; }
2053
2043 // Merges {other} into the current space. Note that this modifies {other}, 2054 // Merges {other} into the current space. Note that this modifies {other},
2044 // e.g., removes its bump pointer area and resets statistics. 2055 // e.g., removes its bump pointer area and resets statistics.
2045 void MergeCompactionSpace(CompactionSpace* other); 2056 void MergeCompactionSpace(CompactionSpace* other);
2046 2057
2058 void DivideUponCompactionSpaces(CompactionSpaceCollection** other, int num,
2059 intptr_t limit);
2060
2061 protected:
2062 void AddMemory(Address start, intptr_t size);
2063
2064 FreeSpace* TryRemoveMemory(intptr_t size_in_bytes);
2065
2047 void MoveOverFreeMemory(PagedSpace* other); 2066 void MoveOverFreeMemory(PagedSpace* other);
2048 2067
2049 virtual bool is_local() { return false; }
2050
2051 protected:
2052 // PagedSpaces that should be included in snapshots have different, i.e., 2068 // PagedSpaces that should be included in snapshots have different, i.e.,
2053 // smaller, initial pages. 2069 // smaller, initial pages.
2054 virtual bool snapshotable() { return true; } 2070 virtual bool snapshotable() { return true; }
2055 2071
2056 FreeList* free_list() { return &free_list_; } 2072 FreeList* free_list() { return &free_list_; }
2057 2073
2058 bool HasPages() { return anchor_.next_page() != &anchor_; } 2074 bool HasPages() { return anchor_.next_page() != &anchor_; }
2059 2075
2060 // Cleans up the space, frees all pages in this space except those belonging 2076 // Cleans up the space, frees all pages in this space except those belonging
2061 // to the initial chunk, uncommits addresses in the initial chunk. 2077 // to the initial chunk, uncommits addresses in the initial chunk.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 // The sweeper threads iterate over the list of pointer and data space pages 2118 // 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 2119 // and sweep these pages concurrently. They will stop sweeping after the
2104 // end_of_unswept_pages_ page. 2120 // end_of_unswept_pages_ page.
2105 Page* end_of_unswept_pages_; 2121 Page* end_of_unswept_pages_;
2106 2122
2107 // Mutex guarding any concurrent access to the space. 2123 // Mutex guarding any concurrent access to the space.
2108 base::Mutex space_mutex_; 2124 base::Mutex space_mutex_;
2109 2125
2110 friend class MarkCompactCollector; 2126 friend class MarkCompactCollector;
2111 friend class PageIterator; 2127 friend class PageIterator;
2128
2129 // Used in cctest.
2130 friend class HeapTester;
2112 }; 2131 };
2113 2132
2114 2133
2115 class NumberAndSizeInfo BASE_EMBEDDED { 2134 class NumberAndSizeInfo BASE_EMBEDDED {
2116 public: 2135 public:
2117 NumberAndSizeInfo() : number_(0), bytes_(0) {} 2136 NumberAndSizeInfo() : number_(0), bytes_(0) {}
2118 2137
2119 int number() const { return number_; } 2138 int number() const { return number_; }
2120 void increment_number(int num) { number_ += num; } 2139 void increment_number(int num) { number_ += num; }
2121 2140
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 count = 0; 3028 count = 0;
3010 } 3029 }
3011 // Must be small, since an iteration is used for lookup. 3030 // Must be small, since an iteration is used for lookup.
3012 static const int kMaxComments = 64; 3031 static const int kMaxComments = 64;
3013 }; 3032 };
3014 #endif 3033 #endif
3015 } // namespace internal 3034 } // namespace internal
3016 } // namespace v8 3035 } // namespace v8
3017 3036
3018 #endif // V8_HEAP_SPACES_H_ 3037 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap/mark-compact.cc ('k') | src/heap/spaces.cc » ('j') | src/heap/spaces.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698