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 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 return (space == CODE_SPACE) ? CodePageAreaSize() | 1266 return (space == CODE_SPACE) ? CodePageAreaSize() |
1267 : Page::kAllocatableMemory; | 1267 : Page::kAllocatableMemory; |
1268 } | 1268 } |
1269 | 1269 |
1270 static intptr_t GetCommitPageSize(); | 1270 static intptr_t GetCommitPageSize(); |
1271 | 1271 |
1272 explicit MemoryAllocator(Isolate* isolate); | 1272 explicit MemoryAllocator(Isolate* isolate); |
1273 | 1273 |
1274 // Initializes its internal bookkeeping structures. | 1274 // Initializes its internal bookkeeping structures. |
1275 // Max capacity of the total space and executable memory limit. | 1275 // Max capacity of the total space and executable memory limit. |
1276 bool SetUp(size_t max_capacity, size_t capacity_executable, | 1276 bool SetUp(size_t max_capacity, size_t code_range_size); |
1277 size_t code_range_size); | |
1278 | 1277 |
1279 void TearDown(); | 1278 void TearDown(); |
1280 | 1279 |
1281 // Allocates a Page from the allocator. AllocationMode is used to indicate | 1280 // Allocates a Page from the allocator. AllocationMode is used to indicate |
1282 // whether pooled allocation, which only works for MemoryChunk::kPageSize, | 1281 // whether pooled allocation, which only works for MemoryChunk::kPageSize, |
1283 // should be tried first. | 1282 // should be tried first. |
1284 template <MemoryAllocator::AllocationMode alloc_mode = kRegular, | 1283 template <MemoryAllocator::AllocationMode alloc_mode = kRegular, |
1285 typename SpaceType> | 1284 typename SpaceType> |
1286 Page* AllocatePage(size_t size, SpaceType* owner, Executability executable); | 1285 Page* AllocatePage(size_t size, SpaceType* owner, Executability executable); |
1287 | 1286 |
(...skipping 10 matching lines...) Expand all Loading... |
1298 | 1297 |
1299 // Returns allocated executable spaces in bytes. | 1298 // Returns allocated executable spaces in bytes. |
1300 size_t SizeExecutable() { return size_executable_.Value(); } | 1299 size_t SizeExecutable() { return size_executable_.Value(); } |
1301 | 1300 |
1302 // Returns the maximum available bytes of heaps. | 1301 // Returns the maximum available bytes of heaps. |
1303 size_t Available() { | 1302 size_t Available() { |
1304 const size_t size = Size(); | 1303 const size_t size = Size(); |
1305 return capacity_ < size ? 0 : capacity_ - size; | 1304 return capacity_ < size ? 0 : capacity_ - size; |
1306 } | 1305 } |
1307 | 1306 |
1308 // Returns the maximum available executable bytes of heaps. | |
1309 size_t AvailableExecutable() { | |
1310 const size_t executable_size = SizeExecutable(); | |
1311 if (capacity_executable_ < executable_size) return 0; | |
1312 return capacity_executable_ - executable_size; | |
1313 } | |
1314 | |
1315 // Returns maximum available bytes that the old space can have. | 1307 // Returns maximum available bytes that the old space can have. |
1316 size_t MaxAvailable() { | 1308 size_t MaxAvailable() { |
1317 return (Available() / Page::kPageSize) * Page::kAllocatableMemory; | 1309 return (Available() / Page::kPageSize) * Page::kAllocatableMemory; |
1318 } | 1310 } |
1319 | 1311 |
1320 // Returns an indication of whether a pointer is in a space that has | 1312 // Returns an indication of whether a pointer is in a space that has |
1321 // been allocated by this MemoryAllocator. | 1313 // been allocated by this MemoryAllocator. |
1322 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { | 1314 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { |
1323 return address < lowest_ever_allocated_.Value() || | 1315 return address < lowest_ever_allocated_.Value() || |
1324 address >= highest_ever_allocated_.Value(); | 1316 address >= highest_ever_allocated_.Value(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 do { | 1395 do { |
1404 ptr = highest_ever_allocated_.Value(); | 1396 ptr = highest_ever_allocated_.Value(); |
1405 } while ((high > ptr) && !highest_ever_allocated_.TrySetValue(ptr, high)); | 1397 } while ((high > ptr) && !highest_ever_allocated_.TrySetValue(ptr, high)); |
1406 } | 1398 } |
1407 | 1399 |
1408 Isolate* isolate_; | 1400 Isolate* isolate_; |
1409 CodeRange* code_range_; | 1401 CodeRange* code_range_; |
1410 | 1402 |
1411 // Maximum space size in bytes. | 1403 // Maximum space size in bytes. |
1412 size_t capacity_; | 1404 size_t capacity_; |
1413 // Maximum subset of capacity_ that can be executable | |
1414 size_t capacity_executable_; | |
1415 | 1405 |
1416 // Allocated space size in bytes. | 1406 // Allocated space size in bytes. |
1417 base::AtomicNumber<size_t> size_; | 1407 base::AtomicNumber<size_t> size_; |
1418 // Allocated executable space size in bytes. | 1408 // Allocated executable space size in bytes. |
1419 base::AtomicNumber<size_t> size_executable_; | 1409 base::AtomicNumber<size_t> size_executable_; |
1420 | 1410 |
1421 // We keep the lowest and highest addresses allocated as a quick way | 1411 // We keep the lowest and highest addresses allocated as a quick way |
1422 // of determining that pointers are outside the heap. The estimate is | 1412 // of determining that pointers are outside the heap. The estimate is |
1423 // conservative, i.e. not all addresses in 'allocated' space are allocated | 1413 // conservative, i.e. not all addresses in 'allocated' space are allocated |
1424 // to our heap. The range is [lowest, highest[, inclusive on the low end | 1414 // to our heap. The range is [lowest, highest[, inclusive on the low end |
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2963 PageIterator old_iterator_; | 2953 PageIterator old_iterator_; |
2964 PageIterator code_iterator_; | 2954 PageIterator code_iterator_; |
2965 PageIterator map_iterator_; | 2955 PageIterator map_iterator_; |
2966 LargePageIterator lo_iterator_; | 2956 LargePageIterator lo_iterator_; |
2967 }; | 2957 }; |
2968 | 2958 |
2969 } // namespace internal | 2959 } // namespace internal |
2970 } // namespace v8 | 2960 } // namespace v8 |
2971 | 2961 |
2972 #endif // V8_HEAP_SPACES_H_ | 2962 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |