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/base/atomicops.h" | 9 #include "src/base/atomicops.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 882 matching lines...) Loading... | |
893 // Allocates a chunk of memory from the large-object portion of | 893 // Allocates a chunk of memory from the large-object portion of |
894 // the code range. On platforms with no separate code range, should | 894 // the code range. On platforms with no separate code range, should |
895 // not be called. | 895 // not be called. |
896 MUST_USE_RESULT Address AllocateRawMemory(const size_t requested_size, | 896 MUST_USE_RESULT Address AllocateRawMemory(const size_t requested_size, |
897 const size_t commit_size, | 897 const size_t commit_size, |
898 size_t* allocated); | 898 size_t* allocated); |
899 bool CommitRawMemory(Address start, size_t length); | 899 bool CommitRawMemory(Address start, size_t length); |
900 bool UncommitRawMemory(Address start, size_t length); | 900 bool UncommitRawMemory(Address start, size_t length); |
901 void FreeRawMemory(Address buf, size_t length); | 901 void FreeRawMemory(Address buf, size_t length); |
902 | 902 |
903 void ReserveEmergencyBlock(); | |
904 void ReleaseEmergencyBlock(); | |
905 | |
903 private: | 906 private: |
904 Isolate* isolate_; | 907 Isolate* isolate_; |
905 | 908 |
906 // The reserved range of virtual memory that all code objects are put in. | 909 // The reserved range of virtual memory that all code objects are put in. |
907 base::VirtualMemory* code_range_; | 910 base::VirtualMemory* code_range_; |
908 // Plain old data class, just a struct plus a constructor. | 911 // Plain old data class, just a struct plus a constructor. |
909 class FreeBlock { | 912 class FreeBlock { |
910 public: | 913 public: |
914 FreeBlock() : start(0), size(0) {} | |
911 FreeBlock(Address start_arg, size_t size_arg) | 915 FreeBlock(Address start_arg, size_t size_arg) |
912 : start(start_arg), size(size_arg) { | 916 : start(start_arg), size(size_arg) { |
913 DCHECK(IsAddressAligned(start, MemoryChunk::kAlignment)); | 917 DCHECK(IsAddressAligned(start, MemoryChunk::kAlignment)); |
914 DCHECK(size >= static_cast<size_t>(Page::kPageSize)); | 918 DCHECK(size >= static_cast<size_t>(Page::kPageSize)); |
915 } | 919 } |
916 FreeBlock(void* start_arg, size_t size_arg) | 920 FreeBlock(void* start_arg, size_t size_arg) |
917 : start(static_cast<Address>(start_arg)), size(size_arg) { | 921 : start(static_cast<Address>(start_arg)), size(size_arg) { |
918 DCHECK(IsAddressAligned(start, MemoryChunk::kAlignment)); | 922 DCHECK(IsAddressAligned(start, MemoryChunk::kAlignment)); |
919 DCHECK(size >= static_cast<size_t>(Page::kPageSize)); | 923 DCHECK(size >= static_cast<size_t>(Page::kPageSize)); |
920 } | 924 } |
921 | 925 |
922 Address start; | 926 Address start; |
923 size_t size; | 927 size_t size; |
924 }; | 928 }; |
925 | 929 |
926 // Freed blocks of memory are added to the free list. When the allocation | 930 // Freed blocks of memory are added to the free list. When the allocation |
927 // list is exhausted, the free list is sorted and merged to make the new | 931 // list is exhausted, the free list is sorted and merged to make the new |
928 // allocation list. | 932 // allocation list. |
929 List<FreeBlock> free_list_; | 933 List<FreeBlock> free_list_; |
930 // Memory is allocated from the free blocks on the allocation list. | 934 // Memory is allocated from the free blocks on the allocation list. |
931 // The block at current_allocation_block_index_ is the current block. | 935 // The block at current_allocation_block_index_ is the current block. |
932 List<FreeBlock> allocation_list_; | 936 List<FreeBlock> allocation_list_; |
933 int current_allocation_block_index_; | 937 int current_allocation_block_index_; |
934 | 938 |
939 FreeBlock emergency_block_; | |
Hannes Payer (out of office)
2014/11/20 08:00:37
Please add a comment that describes the concept of
ulan
2014/11/20 13:49:30
Done.
| |
940 | |
935 // Finds a block on the allocation list that contains at least the | 941 // Finds a block on the allocation list that contains at least the |
936 // requested amount of memory. If none is found, sorts and merges | 942 // requested amount of memory. If none is found, sorts and merges |
937 // the existing free memory blocks, and searches again. | 943 // the existing free memory blocks, and searches again. |
938 // If none can be found, returns false. | 944 // If none can be found, returns false. |
939 bool GetNextAllocationBlock(size_t requested); | 945 bool GetNextAllocationBlock(size_t requested); |
940 // Compares the start addresses of two free blocks. | 946 // Compares the start addresses of two free blocks. |
941 static int CompareFreeBlockAddress(const FreeBlock* left, | 947 static int CompareFreeBlockAddress(const FreeBlock* left, |
942 const FreeBlock* right); | 948 const FreeBlock* right); |
949 bool ReserveBlock(const size_t requested_size, FreeBlock* block); | |
950 void ReleaseBlock(const FreeBlock* block); | |
943 | 951 |
944 DISALLOW_COPY_AND_ASSIGN(CodeRange); | 952 DISALLOW_COPY_AND_ASSIGN(CodeRange); |
945 }; | 953 }; |
946 | 954 |
947 | 955 |
948 class SkipList { | 956 class SkipList { |
949 public: | 957 public: |
950 SkipList() { Clear(); } | 958 SkipList() { Clear(); } |
951 | 959 |
952 void Clear() { | 960 void Clear() { |
(...skipping 1952 matching lines...) Loading... | |
2905 count = 0; | 2913 count = 0; |
2906 } | 2914 } |
2907 // Must be small, since an iteration is used for lookup. | 2915 // Must be small, since an iteration is used for lookup. |
2908 static const int kMaxComments = 64; | 2916 static const int kMaxComments = 64; |
2909 }; | 2917 }; |
2910 #endif | 2918 #endif |
2911 } | 2919 } |
2912 } // namespace v8::internal | 2920 } // namespace v8::internal |
2913 | 2921 |
2914 #endif // V8_HEAP_SPACES_H_ | 2922 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |