OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 // platforms, we support this using the CodeRange object, which reserves and | 808 // platforms, we support this using the CodeRange object, which reserves and |
809 // manages a range of virtual memory. | 809 // manages a range of virtual memory. |
810 class CodeRange { | 810 class CodeRange { |
811 public: | 811 public: |
812 explicit CodeRange(Isolate* isolate); | 812 explicit CodeRange(Isolate* isolate); |
813 ~CodeRange() { TearDown(); } | 813 ~CodeRange() { TearDown(); } |
814 | 814 |
815 // Reserves a range of virtual memory, but does not commit any of it. | 815 // Reserves a range of virtual memory, but does not commit any of it. |
816 // Can only be called once, at heap initialization time. | 816 // Can only be called once, at heap initialization time. |
817 // Returns false on failure. | 817 // Returns false on failure. |
818 bool Setup(const size_t requested_size); | 818 bool SetUp(const size_t requested_size); |
819 | 819 |
820 // Frees the range of virtual memory, and frees the data structures used to | 820 // Frees the range of virtual memory, and frees the data structures used to |
821 // manage it. | 821 // manage it. |
822 void TearDown(); | 822 void TearDown(); |
823 | 823 |
824 bool exists() { return this != NULL && code_range_ != NULL; } | 824 bool exists() { return this != NULL && code_range_ != NULL; } |
825 bool contains(Address address) { | 825 bool contains(Address address) { |
826 if (this == NULL || code_range_ == NULL) return false; | 826 if (this == NULL || code_range_ == NULL) return false; |
827 Address start = static_cast<Address>(code_range_->address()); | 827 Address start = static_cast<Address>(code_range_->address()); |
828 return start <= address && address < start + code_range_->size(); | 828 return start <= address && address < start + code_range_->size(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 // pages for large object space. | 936 // pages for large object space. |
937 // | 937 // |
938 // Each space has to manage it's own pages. | 938 // Each space has to manage it's own pages. |
939 // | 939 // |
940 class MemoryAllocator { | 940 class MemoryAllocator { |
941 public: | 941 public: |
942 explicit MemoryAllocator(Isolate* isolate); | 942 explicit MemoryAllocator(Isolate* isolate); |
943 | 943 |
944 // Initializes its internal bookkeeping structures. | 944 // Initializes its internal bookkeeping structures. |
945 // Max capacity of the total space and executable memory limit. | 945 // Max capacity of the total space and executable memory limit. |
946 bool Setup(intptr_t max_capacity, intptr_t capacity_executable); | 946 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable); |
947 | 947 |
948 void TearDown(); | 948 void TearDown(); |
949 | 949 |
950 Page* AllocatePage(PagedSpace* owner, Executability executable); | 950 Page* AllocatePage(PagedSpace* owner, Executability executable); |
951 | 951 |
952 LargePage* AllocateLargePage(intptr_t object_size, | 952 LargePage* AllocateLargePage(intptr_t object_size, |
953 Executability executable, | 953 Executability executable, |
954 Space* owner); | 954 Space* owner); |
955 | 955 |
956 void Free(MemoryChunk* chunk); | 956 void Free(MemoryChunk* chunk); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 intptr_t max_capacity, | 1412 intptr_t max_capacity, |
1413 AllocationSpace id, | 1413 AllocationSpace id, |
1414 Executability executable); | 1414 Executability executable); |
1415 | 1415 |
1416 virtual ~PagedSpace() {} | 1416 virtual ~PagedSpace() {} |
1417 | 1417 |
1418 // Set up the space using the given address range of virtual memory (from | 1418 // Set up the space using the given address range of virtual memory (from |
1419 // the memory allocator's initial chunk) if possible. If the block of | 1419 // the memory allocator's initial chunk) if possible. If the block of |
1420 // addresses is not big enough to contain a single page-aligned page, a | 1420 // addresses is not big enough to contain a single page-aligned page, a |
1421 // fresh chunk will be allocated. | 1421 // fresh chunk will be allocated. |
1422 bool Setup(); | 1422 bool SetUp(); |
1423 | 1423 |
1424 // Returns true if the space has been successfully set up and not | 1424 // Returns true if the space has been successfully set up and not |
1425 // subsequently torn down. | 1425 // subsequently torn down. |
1426 bool HasBeenSetup(); | 1426 bool HasBeenSetUp(); |
1427 | 1427 |
1428 // Cleans up the space, frees all pages in this space except those belonging | 1428 // Cleans up the space, frees all pages in this space except those belonging |
1429 // to the initial chunk, uncommits addresses in the initial chunk. | 1429 // to the initial chunk, uncommits addresses in the initial chunk. |
1430 void TearDown(); | 1430 void TearDown(); |
1431 | 1431 |
1432 // Checks whether an object/address is in this space. | 1432 // Checks whether an object/address is in this space. |
1433 inline bool Contains(Address a); | 1433 inline bool Contains(Address a); |
1434 bool Contains(HeapObject* o) { return Contains(o->address()); } | 1434 bool Contains(HeapObject* o) { return Contains(o->address()); } |
1435 | 1435 |
1436 // Given an address occupied by a live object, return that object if it is | 1436 // Given an address occupied by a live object, return that object if it is |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 // Constructor. | 1801 // Constructor. |
1802 SemiSpace(Heap* heap, SemiSpaceId semispace) | 1802 SemiSpace(Heap* heap, SemiSpaceId semispace) |
1803 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 1803 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
1804 start_(NULL), | 1804 start_(NULL), |
1805 age_mark_(NULL), | 1805 age_mark_(NULL), |
1806 id_(semispace), | 1806 id_(semispace), |
1807 anchor_(this), | 1807 anchor_(this), |
1808 current_page_(NULL) { } | 1808 current_page_(NULL) { } |
1809 | 1809 |
1810 // Sets up the semispace using the given chunk. | 1810 // Sets up the semispace using the given chunk. |
1811 bool Setup(Address start, int initial_capacity, int maximum_capacity); | 1811 bool SetUp(Address start, int initial_capacity, int maximum_capacity); |
1812 | 1812 |
1813 // Tear down the space. Heap memory was not allocated by the space, so it | 1813 // Tear down the space. Heap memory was not allocated by the space, so it |
1814 // is not deallocated here. | 1814 // is not deallocated here. |
1815 void TearDown(); | 1815 void TearDown(); |
1816 | 1816 |
1817 // True if the space has been set up but not torn down. | 1817 // True if the space has been set up but not torn down. |
1818 bool HasBeenSetup() { return start_ != NULL; } | 1818 bool HasBeenSetUp() { return start_ != NULL; } |
1819 | 1819 |
1820 // Grow the semispace to the new capacity. The new capacity | 1820 // Grow the semispace to the new capacity. The new capacity |
1821 // requested must be larger than the current capacity and less than | 1821 // requested must be larger than the current capacity and less than |
1822 // the maximum capacity. | 1822 // the maximum capacity. |
1823 bool GrowTo(int new_capacity); | 1823 bool GrowTo(int new_capacity); |
1824 | 1824 |
1825 // Shrinks the semispace to the new capacity. The new capacity | 1825 // Shrinks the semispace to the new capacity. The new capacity |
1826 // requested must be more than the amount of used memory in the | 1826 // requested must be more than the amount of used memory in the |
1827 // semispace and less than the current capacity. | 1827 // semispace and less than the current capacity. |
1828 bool ShrinkTo(int new_capacity); | 1828 bool ShrinkTo(int new_capacity); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 public: | 2047 public: |
2048 // Constructor. | 2048 // Constructor. |
2049 explicit NewSpace(Heap* heap) | 2049 explicit NewSpace(Heap* heap) |
2050 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 2050 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
2051 to_space_(heap, kToSpace), | 2051 to_space_(heap, kToSpace), |
2052 from_space_(heap, kFromSpace), | 2052 from_space_(heap, kFromSpace), |
2053 reservation_(), | 2053 reservation_(), |
2054 inline_allocation_limit_step_(0) {} | 2054 inline_allocation_limit_step_(0) {} |
2055 | 2055 |
2056 // Sets up the new space using the given chunk. | 2056 // Sets up the new space using the given chunk. |
2057 bool Setup(int reserved_semispace_size_, int max_semispace_size); | 2057 bool SetUp(int reserved_semispace_size_, int max_semispace_size); |
2058 | 2058 |
2059 // Tears down the space. Heap memory was not allocated by the space, so it | 2059 // Tears down the space. Heap memory was not allocated by the space, so it |
2060 // is not deallocated here. | 2060 // is not deallocated here. |
2061 void TearDown(); | 2061 void TearDown(); |
2062 | 2062 |
2063 // True if the space has been set up but not torn down. | 2063 // True if the space has been set up but not torn down. |
2064 bool HasBeenSetup() { | 2064 bool HasBeenSetUp() { |
2065 return to_space_.HasBeenSetup() && from_space_.HasBeenSetup(); | 2065 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp(); |
2066 } | 2066 } |
2067 | 2067 |
2068 // Flip the pair of spaces. | 2068 // Flip the pair of spaces. |
2069 void Flip(); | 2069 void Flip(); |
2070 | 2070 |
2071 // Grow the capacity of the semispaces. Assumes that they are not at | 2071 // Grow the capacity of the semispaces. Assumes that they are not at |
2072 // their maximum capacity. | 2072 // their maximum capacity. |
2073 void Grow(); | 2073 void Grow(); |
2074 | 2074 |
2075 // Shrink the capacity of the semispaces. | 2075 // Shrink the capacity of the semispaces. |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 // extra padding bytes (Page::kPageSize + Page::kObjectStartOffset). | 2454 // extra padding bytes (Page::kPageSize + Page::kObjectStartOffset). |
2455 // A large object always starts at Page::kObjectStartOffset to a page. | 2455 // A large object always starts at Page::kObjectStartOffset to a page. |
2456 // Large objects do not move during garbage collections. | 2456 // Large objects do not move during garbage collections. |
2457 | 2457 |
2458 class LargeObjectSpace : public Space { | 2458 class LargeObjectSpace : public Space { |
2459 public: | 2459 public: |
2460 LargeObjectSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id); | 2460 LargeObjectSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id); |
2461 virtual ~LargeObjectSpace() {} | 2461 virtual ~LargeObjectSpace() {} |
2462 | 2462 |
2463 // Initializes internal data structures. | 2463 // Initializes internal data structures. |
2464 bool Setup(); | 2464 bool SetUp(); |
2465 | 2465 |
2466 // Releases internal resources, frees objects in this space. | 2466 // Releases internal resources, frees objects in this space. |
2467 void TearDown(); | 2467 void TearDown(); |
2468 | 2468 |
2469 static intptr_t ObjectSizeFor(intptr_t chunk_size) { | 2469 static intptr_t ObjectSizeFor(intptr_t chunk_size) { |
2470 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; | 2470 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; |
2471 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; | 2471 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; |
2472 } | 2472 } |
2473 | 2473 |
2474 // Shared implementation of AllocateRaw, AllocateRawCode and | 2474 // Shared implementation of AllocateRaw, AllocateRawCode and |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2630 } | 2630 } |
2631 // Must be small, since an iteration is used for lookup. | 2631 // Must be small, since an iteration is used for lookup. |
2632 static const int kMaxComments = 64; | 2632 static const int kMaxComments = 64; |
2633 }; | 2633 }; |
2634 #endif | 2634 #endif |
2635 | 2635 |
2636 | 2636 |
2637 } } // namespace v8::internal | 2637 } } // namespace v8::internal |
2638 | 2638 |
2639 #endif // V8_SPACES_H_ | 2639 #endif // V8_SPACES_H_ |
OLD | NEW |