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" |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 Address OffsetToAddress(int offset) { | 807 Address OffsetToAddress(int offset) { |
808 DCHECK_PAGE_OFFSET(offset); | 808 DCHECK_PAGE_OFFSET(offset); |
809 return address() + offset; | 809 return address() + offset; |
810 } | 810 } |
811 | 811 |
812 // --------------------------------------------------------------------- | 812 // --------------------------------------------------------------------- |
813 | 813 |
814 // Page size in bytes. This must be a multiple of the OS page size. | 814 // Page size in bytes. This must be a multiple of the OS page size. |
815 static const int kPageSize = 1 << kPageSizeBits; | 815 static const int kPageSize = 1 << kPageSizeBits; |
816 | 816 |
817 // Maximum object size that gets allocated into regular pages. Objects larger | 817 // Maximum object size that fits in a page. Objects larger than that size |
818 // than that size are allocated in large object space and are never moved in | 818 // are allocated in large object space and are never moved in memory. This |
819 // memory. This also applies to new space allocation, since objects are never | 819 // also applies to new space allocation, since objects are never migrated |
820 // migrated from new space to large object space. Takes double alignment into | 820 // from new space to large object space. Takes double alignment into account. |
821 // account. | |
822 static const int kMaxRegularHeapObjectSize = kPageSize - kObjectStartOffset; | 821 static const int kMaxRegularHeapObjectSize = kPageSize - kObjectStartOffset; |
823 | 822 |
824 static const int kAllocatableMemory = kPageSize - kObjectStartOffset; | |
825 | |
826 // Page size mask. | 823 // Page size mask. |
827 static const intptr_t kPageAlignmentMask = (1 << kPageSizeBits) - 1; | 824 static const intptr_t kPageAlignmentMask = (1 << kPageSizeBits) - 1; |
828 | 825 |
829 inline void ClearGCFields(); | 826 inline void ClearGCFields(); |
830 | 827 |
831 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, | 828 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, |
832 Executability executable, PagedSpace* owner); | 829 Executability executable, PagedSpace* owner); |
833 | 830 |
834 void InitializeAsAnchor(PagedSpace* owner); | 831 void InitializeAsAnchor(PagedSpace* owner); |
835 | 832 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 | 1162 |
1166 // Returns the maximum available executable bytes of heaps. | 1163 // Returns the maximum available executable bytes of heaps. |
1167 intptr_t AvailableExecutable() { | 1164 intptr_t AvailableExecutable() { |
1168 intptr_t executable_size = SizeExecutable(); | 1165 intptr_t executable_size = SizeExecutable(); |
1169 if (capacity_executable_ < executable_size) return 0; | 1166 if (capacity_executable_ < executable_size) return 0; |
1170 return capacity_executable_ - executable_size; | 1167 return capacity_executable_ - executable_size; |
1171 } | 1168 } |
1172 | 1169 |
1173 // Returns maximum available bytes that the old space can have. | 1170 // Returns maximum available bytes that the old space can have. |
1174 intptr_t MaxAvailable() { | 1171 intptr_t MaxAvailable() { |
1175 return (Available() / Page::kPageSize) * Page::kAllocatableMemory; | 1172 return (Available() / Page::kPageSize) * Page::kMaxRegularHeapObjectSize; |
1176 } | 1173 } |
1177 | 1174 |
1178 // Returns an indication of whether a pointer is in a space that has | 1175 // Returns an indication of whether a pointer is in a space that has |
1179 // been allocated by this MemoryAllocator. | 1176 // been allocated by this MemoryAllocator. |
1180 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { | 1177 V8_INLINE bool IsOutsideAllocatedSpace(const void* address) { |
1181 return address < lowest_ever_allocated_.Value() || | 1178 return address < lowest_ever_allocated_.Value() || |
1182 address >= highest_ever_allocated_.Value(); | 1179 address >= highest_ever_allocated_.Value(); |
1183 } | 1180 } |
1184 | 1181 |
1185 #ifdef DEBUG | 1182 #ifdef DEBUG |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 | 1238 |
1242 static int CodePageAreaEndOffset(); | 1239 static int CodePageAreaEndOffset(); |
1243 | 1240 |
1244 static int CodePageAreaSize() { | 1241 static int CodePageAreaSize() { |
1245 return CodePageAreaEndOffset() - CodePageAreaStartOffset(); | 1242 return CodePageAreaEndOffset() - CodePageAreaStartOffset(); |
1246 } | 1243 } |
1247 | 1244 |
1248 static int PageAreaSize(AllocationSpace space) { | 1245 static int PageAreaSize(AllocationSpace space) { |
1249 DCHECK_NE(LO_SPACE, space); | 1246 DCHECK_NE(LO_SPACE, space); |
1250 return (space == CODE_SPACE) ? CodePageAreaSize() | 1247 return (space == CODE_SPACE) ? CodePageAreaSize() |
1251 : Page::kAllocatableMemory; | 1248 : Page::kMaxRegularHeapObjectSize; |
1252 } | 1249 } |
1253 | 1250 |
1254 MUST_USE_RESULT bool CommitExecutableMemory(base::VirtualMemory* vm, | 1251 MUST_USE_RESULT bool CommitExecutableMemory(base::VirtualMemory* vm, |
1255 Address start, size_t commit_size, | 1252 Address start, size_t commit_size, |
1256 size_t reserved_size); | 1253 size_t reserved_size); |
1257 | 1254 |
1258 private: | 1255 private: |
1259 Isolate* isolate_; | 1256 Isolate* isolate_; |
1260 | 1257 |
1261 // Maximum space size in bytes. | 1258 // Maximum space size in bytes. |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 FreeListCategory* large_list() { return &large_list_; } | 1693 FreeListCategory* large_list() { return &large_list_; } |
1697 FreeListCategory* huge_list() { return &huge_list_; } | 1694 FreeListCategory* huge_list() { return &huge_list_; } |
1698 | 1695 |
1699 PagedSpace* owner() { return owner_; } | 1696 PagedSpace* owner() { return owner_; } |
1700 intptr_t wasted_bytes() { return wasted_bytes_; } | 1697 intptr_t wasted_bytes() { return wasted_bytes_; } |
1701 base::Mutex* mutex() { return &mutex_; } | 1698 base::Mutex* mutex() { return &mutex_; } |
1702 | 1699 |
1703 private: | 1700 private: |
1704 // The size range of blocks, in bytes. | 1701 // The size range of blocks, in bytes. |
1705 static const int kMinBlockSize = 3 * kPointerSize; | 1702 static const int kMinBlockSize = 3 * kPointerSize; |
1706 static const int kMaxBlockSize = Page::kAllocatableMemory; | 1703 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; |
1707 | 1704 |
1708 static const int kSmallListMin = 0x1f * kPointerSize; | 1705 static const int kSmallListMin = 0x1f * kPointerSize; |
1709 static const int kSmallListMax = 0xff * kPointerSize; | 1706 static const int kSmallListMax = 0xff * kPointerSize; |
1710 static const int kMediumListMax = 0x7ff * kPointerSize; | 1707 static const int kMediumListMax = 0x7ff * kPointerSize; |
1711 static const int kLargeListMax = 0x3fff * kPointerSize; | 1708 static const int kLargeListMax = 0x3fff * kPointerSize; |
1712 static const int kSmallAllocationMax = kSmallListMin; | 1709 static const int kSmallAllocationMax = kSmallListMin; |
1713 static const int kMediumAllocationMax = kSmallListMax; | 1710 static const int kMediumAllocationMax = kSmallListMax; |
1714 static const int kLargeAllocationMax = kMediumListMax; | 1711 static const int kLargeAllocationMax = kMediumListMax; |
1715 | 1712 |
1716 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); | 1713 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 | 2113 |
2117 class NewSpacePage : public MemoryChunk { | 2114 class NewSpacePage : public MemoryChunk { |
2118 public: | 2115 public: |
2119 // GC related flags copied from from-space to to-space when | 2116 // GC related flags copied from from-space to to-space when |
2120 // flipping semispaces. | 2117 // flipping semispaces. |
2121 static const intptr_t kCopyOnFlipFlagsMask = | 2118 static const intptr_t kCopyOnFlipFlagsMask = |
2122 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) | | 2119 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) | |
2123 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING) | | 2120 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING) | |
2124 (1 << MemoryChunk::SCAN_ON_SCAVENGE); | 2121 (1 << MemoryChunk::SCAN_ON_SCAVENGE); |
2125 | 2122 |
2126 static const int kAreaSize = Page::kAllocatableMemory; | 2123 static const int kAreaSize = Page::kMaxRegularHeapObjectSize; |
2127 | 2124 |
2128 inline NewSpacePage* next_page() { | 2125 inline NewSpacePage* next_page() { |
2129 return static_cast<NewSpacePage*>(next_chunk()); | 2126 return static_cast<NewSpacePage*>(next_chunk()); |
2130 } | 2127 } |
2131 | 2128 |
2132 inline void set_next_page(NewSpacePage* page) { set_next_chunk(page); } | 2129 inline void set_next_page(NewSpacePage* page) { set_next_chunk(page); } |
2133 | 2130 |
2134 inline NewSpacePage* prev_page() { | 2131 inline NewSpacePage* prev_page() { |
2135 return static_cast<NewSpacePage*>(prev_chunk()); | 2132 return static_cast<NewSpacePage*>(prev_chunk()); |
2136 } | 2133 } |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2835 return RoundDown(size, Map::kSize); | 2832 return RoundDown(size, Map::kSize); |
2836 } else { | 2833 } else { |
2837 return (size / Map::kSize) * Map::kSize; | 2834 return (size / Map::kSize) * Map::kSize; |
2838 } | 2835 } |
2839 } | 2836 } |
2840 | 2837 |
2841 protected: | 2838 protected: |
2842 virtual void VerifyObject(HeapObject* obj); | 2839 virtual void VerifyObject(HeapObject* obj); |
2843 | 2840 |
2844 private: | 2841 private: |
2845 static const int kMapsPerPage = Page::kAllocatableMemory / Map::kSize; | 2842 static const int kMapsPerPage = Page::kMaxRegularHeapObjectSize / Map::kSize; |
2846 | 2843 |
2847 // Do map space compaction if there is a page gap. | 2844 // Do map space compaction if there is a page gap. |
2848 int CompactionThreshold() { | 2845 int CompactionThreshold() { |
2849 return kMapsPerPage * (max_map_space_pages_ - 1); | 2846 return kMapsPerPage * (max_map_space_pages_ - 1); |
2850 } | 2847 } |
2851 | 2848 |
2852 const int max_map_space_pages_; | 2849 const int max_map_space_pages_; |
2853 }; | 2850 }; |
2854 | 2851 |
2855 | 2852 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 count = 0; | 2987 count = 0; |
2991 } | 2988 } |
2992 // Must be small, since an iteration is used for lookup. | 2989 // Must be small, since an iteration is used for lookup. |
2993 static const int kMaxComments = 64; | 2990 static const int kMaxComments = 64; |
2994 }; | 2991 }; |
2995 #endif | 2992 #endif |
2996 } // namespace internal | 2993 } // namespace internal |
2997 } // namespace v8 | 2994 } // namespace v8 |
2998 | 2995 |
2999 #endif // V8_HEAP_SPACES_H_ | 2996 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |