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; |
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 Loading... |
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 block of at least {size_in_bytes} size. |
| 1731 // |
| 1732 // Can be used concurrently. |
| 1733 MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t size_in_bytes); |
| 1734 |
1729 bool IsEmpty() { | 1735 bool IsEmpty() { |
1730 return small_list_.IsEmpty() && medium_list_.IsEmpty() && | 1736 return small_list_.IsEmpty() && medium_list_.IsEmpty() && |
1731 large_list_.IsEmpty() && huge_list_.IsEmpty(); | 1737 large_list_.IsEmpty() && huge_list_.IsEmpty(); |
1732 } | 1738 } |
1733 | 1739 |
1734 #ifdef DEBUG | 1740 #ifdef DEBUG |
1735 void Zap(); | 1741 void Zap(); |
1736 intptr_t SumFreeLists(); | 1742 intptr_t SumFreeLists(); |
1737 bool IsVeryLong(); | 1743 bool IsVeryLong(); |
1738 #endif | 1744 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 return &large_list_; | 1779 return &large_list_; |
1774 case kHuge: | 1780 case kHuge: |
1775 return &huge_list_; | 1781 return &huge_list_; |
1776 default: | 1782 default: |
1777 UNREACHABLE(); | 1783 UNREACHABLE(); |
1778 } | 1784 } |
1779 UNREACHABLE(); | 1785 UNREACHABLE(); |
1780 return nullptr; | 1786 return nullptr; |
1781 } | 1787 } |
1782 | 1788 |
1783 | |
1784 PagedSpace* owner_; | 1789 PagedSpace* owner_; |
1785 Heap* heap_; | 1790 Heap* heap_; |
1786 base::Mutex mutex_; | 1791 base::Mutex mutex_; |
1787 intptr_t wasted_bytes_; | 1792 intptr_t wasted_bytes_; |
1788 FreeListCategory small_list_; | 1793 FreeListCategory small_list_; |
1789 FreeListCategory medium_list_; | 1794 FreeListCategory medium_list_; |
1790 FreeListCategory large_list_; | 1795 FreeListCategory large_list_; |
1791 FreeListCategory huge_list_; | 1796 FreeListCategory huge_list_; |
1792 | 1797 |
1793 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1798 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 void EvictEvacuationCandidatesFromFreeLists(); | 2038 void EvictEvacuationCandidatesFromFreeLists(); |
2034 | 2039 |
2035 bool CanExpand(size_t size); | 2040 bool CanExpand(size_t size); |
2036 | 2041 |
2037 // Returns the number of total pages in this space. | 2042 // Returns the number of total pages in this space. |
2038 int CountTotalPages(); | 2043 int CountTotalPages(); |
2039 | 2044 |
2040 // Return size of allocatable area on a page in this space. | 2045 // Return size of allocatable area on a page in this space. |
2041 inline int AreaSize() { return area_size_; } | 2046 inline int AreaSize() { return area_size_; } |
2042 | 2047 |
| 2048 virtual bool is_local() { return false; } |
| 2049 |
2043 // Merges {other} into the current space. Note that this modifies {other}, | 2050 // Merges {other} into the current space. Note that this modifies {other}, |
2044 // e.g., removes its bump pointer area and resets statistics. | 2051 // e.g., removes its bump pointer area and resets statistics. |
2045 void MergeCompactionSpace(CompactionSpace* other); | 2052 void MergeCompactionSpace(CompactionSpace* other); |
2046 | 2053 |
| 2054 void DivideUponCompactionSpaces(CompactionSpaceCollection** other, int num, |
| 2055 intptr_t limit); |
| 2056 |
| 2057 protected: |
| 2058 void AddMemory(Address start, intptr_t size); |
| 2059 |
| 2060 FreeSpace* TryRemoveMemory(intptr_t size_in_bytes); |
| 2061 |
2047 void MoveOverFreeMemory(PagedSpace* other); | 2062 void MoveOverFreeMemory(PagedSpace* other); |
2048 | 2063 |
2049 virtual bool is_local() { return false; } | |
2050 | |
2051 protected: | |
2052 // PagedSpaces that should be included in snapshots have different, i.e., | 2064 // PagedSpaces that should be included in snapshots have different, i.e., |
2053 // smaller, initial pages. | 2065 // smaller, initial pages. |
2054 virtual bool snapshotable() { return true; } | 2066 virtual bool snapshotable() { return true; } |
2055 | 2067 |
2056 FreeList* free_list() { return &free_list_; } | 2068 FreeList* free_list() { return &free_list_; } |
2057 | 2069 |
2058 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2070 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2059 | 2071 |
2060 // Cleans up the space, frees all pages in this space except those belonging | 2072 // Cleans up the space, frees all pages in this space except those belonging |
2061 // to the initial chunk, uncommits addresses in the initial chunk. | 2073 // to the initial chunk, uncommits addresses in the initial chunk. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2102 // The sweeper threads iterate over the list of pointer and data space pages | 2114 // 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 | 2115 // and sweep these pages concurrently. They will stop sweeping after the |
2104 // end_of_unswept_pages_ page. | 2116 // end_of_unswept_pages_ page. |
2105 Page* end_of_unswept_pages_; | 2117 Page* end_of_unswept_pages_; |
2106 | 2118 |
2107 // Mutex guarding any concurrent access to the space. | 2119 // Mutex guarding any concurrent access to the space. |
2108 base::Mutex space_mutex_; | 2120 base::Mutex space_mutex_; |
2109 | 2121 |
2110 friend class MarkCompactCollector; | 2122 friend class MarkCompactCollector; |
2111 friend class PageIterator; | 2123 friend class PageIterator; |
| 2124 |
| 2125 // Used in cctest. |
| 2126 friend class HeapTester; |
2112 }; | 2127 }; |
2113 | 2128 |
2114 | 2129 |
2115 class NumberAndSizeInfo BASE_EMBEDDED { | 2130 class NumberAndSizeInfo BASE_EMBEDDED { |
2116 public: | 2131 public: |
2117 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 2132 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
2118 | 2133 |
2119 int number() const { return number_; } | 2134 int number() const { return number_; } |
2120 void increment_number(int num) { number_ += num; } | 2135 void increment_number(int num) { number_ += num; } |
2121 | 2136 |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3009 count = 0; | 3024 count = 0; |
3010 } | 3025 } |
3011 // Must be small, since an iteration is used for lookup. | 3026 // Must be small, since an iteration is used for lookup. |
3012 static const int kMaxComments = 64; | 3027 static const int kMaxComments = 64; |
3013 }; | 3028 }; |
3014 #endif | 3029 #endif |
3015 } // namespace internal | 3030 } // namespace internal |
3016 } // namespace v8 | 3031 } // namespace v8 |
3017 | 3032 |
3018 #endif // V8_HEAP_SPACES_H_ | 3033 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |