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 <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 kRegular, | 1230 kRegular, |
1231 kPooled, | 1231 kPooled, |
1232 }; | 1232 }; |
1233 | 1233 |
1234 enum FreeMode { | 1234 enum FreeMode { |
1235 kFull, | 1235 kFull, |
1236 kPreFreeAndQueue, | 1236 kPreFreeAndQueue, |
1237 kPooledAndQueue, | 1237 kPooledAndQueue, |
1238 }; | 1238 }; |
1239 | 1239 |
1240 static int CodePageGuardStartOffset(); | 1240 static size_t CodePageGuardStartOffset(); |
1241 | 1241 |
1242 static int CodePageGuardSize(); | 1242 static size_t CodePageGuardSize(); |
1243 | 1243 |
1244 static int CodePageAreaStartOffset(); | 1244 static size_t CodePageAreaStartOffset(); |
1245 | 1245 |
1246 static int CodePageAreaEndOffset(); | 1246 static size_t CodePageAreaEndOffset(); |
1247 | 1247 |
1248 static int CodePageAreaSize() { | 1248 static size_t CodePageAreaSize() { |
1249 return CodePageAreaEndOffset() - CodePageAreaStartOffset(); | 1249 return CodePageAreaEndOffset() - CodePageAreaStartOffset(); |
1250 } | 1250 } |
1251 | 1251 |
1252 static int PageAreaSize(AllocationSpace space) { | 1252 static size_t PageAreaSize(AllocationSpace space) { |
1253 DCHECK_NE(LO_SPACE, space); | 1253 DCHECK_NE(LO_SPACE, space); |
1254 return (space == CODE_SPACE) ? CodePageAreaSize() | 1254 return (space == CODE_SPACE) ? CodePageAreaSize() |
1255 : Page::kAllocatableMemory; | 1255 : Page::kAllocatableMemory; |
1256 } | 1256 } |
1257 | 1257 |
1258 explicit MemoryAllocator(Isolate* isolate); | 1258 explicit MemoryAllocator(Isolate* isolate); |
1259 | 1259 |
1260 // Initializes its internal bookkeeping structures. | 1260 // Initializes its internal bookkeeping structures. |
1261 // Max capacity of the total space and executable memory limit. | 1261 // Max capacity of the total space and executable memory limit. |
1262 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable, | 1262 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable, |
1263 intptr_t code_range_size); | 1263 intptr_t code_range_size); |
1264 | 1264 |
1265 void TearDown(); | 1265 void TearDown(); |
1266 | 1266 |
1267 // Allocates a Page from the allocator. AllocationMode is used to indicate | 1267 // Allocates a Page from the allocator. AllocationMode is used to indicate |
1268 // whether pooled allocation, which only works for MemoryChunk::kPageSize, | 1268 // whether pooled allocation, which only works for MemoryChunk::kPageSize, |
1269 // should be tried first. | 1269 // should be tried first. |
1270 template <MemoryAllocator::AllocationMode alloc_mode = kRegular, | 1270 template <MemoryAllocator::AllocationMode alloc_mode = kRegular, |
1271 typename SpaceType> | 1271 typename SpaceType> |
1272 Page* AllocatePage(intptr_t size, SpaceType* owner, Executability executable); | 1272 Page* AllocatePage(size_t size, SpaceType* owner, Executability executable); |
1273 | 1273 |
1274 LargePage* AllocateLargePage(intptr_t size, LargeObjectSpace* owner, | 1274 LargePage* AllocateLargePage(size_t size, LargeObjectSpace* owner, |
1275 Executability executable); | 1275 Executability executable); |
1276 | 1276 |
1277 template <MemoryAllocator::FreeMode mode = kFull> | 1277 template <MemoryAllocator::FreeMode mode = kFull> |
1278 void Free(MemoryChunk* chunk); | 1278 void Free(MemoryChunk* chunk); |
1279 | 1279 |
1280 bool CanFreeMemoryChunk(MemoryChunk* chunk); | 1280 bool CanFreeMemoryChunk(MemoryChunk* chunk); |
1281 | 1281 |
1282 // Returns allocated spaces in bytes. | 1282 // Returns allocated spaces in bytes. |
1283 size_t Size() { return size_.Value(); } | 1283 size_t Size() { return size_.Value(); } |
1284 | 1284 |
(...skipping 21 matching lines...) Expand all Loading... |
1306 // Returns an indication of whether a pointer is in a space that has | 1306 // Returns an indication of whether a pointer is in a space that has |
1307 // been allocated by this MemoryAllocator. | 1307 // been allocated by this MemoryAllocator. |
1308 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { | 1308 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { |
1309 return address < lowest_ever_allocated_.Value() || | 1309 return address < lowest_ever_allocated_.Value() || |
1310 address >= highest_ever_allocated_.Value(); | 1310 address >= highest_ever_allocated_.Value(); |
1311 } | 1311 } |
1312 | 1312 |
1313 // Returns a MemoryChunk in which the memory region from commit_area_size to | 1313 // Returns a MemoryChunk in which the memory region from commit_area_size to |
1314 // reserve_area_size of the chunk area is reserved but not committed, it | 1314 // reserve_area_size of the chunk area is reserved but not committed, it |
1315 // could be committed later by calling MemoryChunk::CommitArea. | 1315 // could be committed later by calling MemoryChunk::CommitArea. |
1316 MemoryChunk* AllocateChunk(intptr_t reserve_area_size, | 1316 MemoryChunk* AllocateChunk(size_t reserve_area_size, size_t commit_area_size, |
1317 intptr_t commit_area_size, | |
1318 Executability executable, Space* space); | 1317 Executability executable, Space* space); |
1319 | 1318 |
1320 void ShrinkChunk(MemoryChunk* chunk, size_t bytes_to_shrink); | 1319 void ShrinkChunk(MemoryChunk* chunk, size_t bytes_to_shrink); |
1321 | 1320 |
1322 Address ReserveAlignedMemory(size_t requested, size_t alignment, | 1321 Address ReserveAlignedMemory(size_t requested, size_t alignment, |
1323 base::VirtualMemory* controller); | 1322 base::VirtualMemory* controller); |
1324 Address AllocateAlignedMemory(size_t reserve_size, size_t commit_size, | 1323 Address AllocateAlignedMemory(size_t reserve_size, size_t commit_size, |
1325 size_t alignment, Executability executable, | 1324 size_t alignment, Executability executable, |
1326 base::VirtualMemory* controller); | 1325 base::VirtualMemory* controller); |
1327 | 1326 |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 Page* LastPage() { return anchor_.prev_page(); } | 2112 Page* LastPage() { return anchor_.prev_page(); } |
2114 | 2113 |
2115 void EvictEvacuationCandidatesFromLinearAllocationArea(); | 2114 void EvictEvacuationCandidatesFromLinearAllocationArea(); |
2116 | 2115 |
2117 bool CanExpand(size_t size); | 2116 bool CanExpand(size_t size); |
2118 | 2117 |
2119 // Returns the number of total pages in this space. | 2118 // Returns the number of total pages in this space. |
2120 int CountTotalPages(); | 2119 int CountTotalPages(); |
2121 | 2120 |
2122 // Return size of allocatable area on a page in this space. | 2121 // Return size of allocatable area on a page in this space. |
2123 inline int AreaSize() { return area_size_; } | 2122 inline int AreaSize() { return static_cast<int>(area_size_); } |
2124 | 2123 |
2125 virtual bool is_local() { return false; } | 2124 virtual bool is_local() { return false; } |
2126 | 2125 |
2127 // Merges {other} into the current space. Note that this modifies {other}, | 2126 // Merges {other} into the current space. Note that this modifies {other}, |
2128 // e.g., removes its bump pointer area and resets statistics. | 2127 // e.g., removes its bump pointer area and resets statistics. |
2129 void MergeCompactionSpace(CompactionSpace* other); | 2128 void MergeCompactionSpace(CompactionSpace* other); |
2130 | 2129 |
2131 // Refills the free list from the corresponding free list filled by the | 2130 // Refills the free list from the corresponding free list filled by the |
2132 // sweeper. | 2131 // sweeper. |
2133 virtual void RefillFreeList(); | 2132 virtual void RefillFreeList(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 | 2175 |
2177 // If sweeping is still in progress try to sweep unswept pages. If that is | 2176 // If sweeping is still in progress try to sweep unswept pages. If that is |
2178 // not successful, wait for the sweeper threads and re-try free-list | 2177 // not successful, wait for the sweeper threads and re-try free-list |
2179 // allocation. | 2178 // allocation. |
2180 MUST_USE_RESULT virtual HeapObject* SweepAndRetryAllocation( | 2179 MUST_USE_RESULT virtual HeapObject* SweepAndRetryAllocation( |
2181 int size_in_bytes); | 2180 int size_in_bytes); |
2182 | 2181 |
2183 // Slow path of AllocateRaw. This function is space-dependent. | 2182 // Slow path of AllocateRaw. This function is space-dependent. |
2184 MUST_USE_RESULT HeapObject* SlowAllocateRaw(int size_in_bytes); | 2183 MUST_USE_RESULT HeapObject* SlowAllocateRaw(int size_in_bytes); |
2185 | 2184 |
2186 int area_size_; | 2185 size_t area_size_; |
2187 | 2186 |
2188 // Accounting information for this space. | 2187 // Accounting information for this space. |
2189 AllocationStats accounting_stats_; | 2188 AllocationStats accounting_stats_; |
2190 | 2189 |
2191 // The dummy page that anchors the double linked list of pages. | 2190 // The dummy page that anchors the double linked list of pages. |
2192 Page anchor_; | 2191 Page anchor_; |
2193 | 2192 |
2194 // The space's free list. | 2193 // The space's free list. |
2195 FreeList free_list_; | 2194 FreeList free_list_; |
2196 | 2195 |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2947 PageIterator old_iterator_; | 2946 PageIterator old_iterator_; |
2948 PageIterator code_iterator_; | 2947 PageIterator code_iterator_; |
2949 PageIterator map_iterator_; | 2948 PageIterator map_iterator_; |
2950 LargePageIterator lo_iterator_; | 2949 LargePageIterator lo_iterator_; |
2951 }; | 2950 }; |
2952 | 2951 |
2953 } // namespace internal | 2952 } // namespace internal |
2954 } // namespace v8 | 2953 } // namespace v8 |
2955 | 2954 |
2956 #endif // V8_HEAP_SPACES_H_ | 2955 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |