| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_SPACES_H_ | 28 #ifndef V8_SPACES_H_ |
| 29 #define V8_SPACES_H_ | 29 #define V8_SPACES_H_ |
| 30 | 30 |
| 31 #include "atomicops.h" |
| 31 #include "list-inl.h" | 32 #include "list-inl.h" |
| 32 #include "log.h" | 33 #include "log.h" |
| 33 | 34 |
| 34 namespace v8 { | 35 namespace v8 { |
| 35 namespace internal { | 36 namespace internal { |
| 36 | 37 |
| 37 class Isolate; | 38 class Isolate; |
| 38 | 39 |
| 39 // ----------------------------------------------------------------------------- | 40 // ----------------------------------------------------------------------------- |
| 40 // Heap structures: | 41 // Heap structures: |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 // Reports statistic info of the space. | 656 // Reports statistic info of the space. |
| 656 void ReportStatistics(); | 657 void ReportStatistics(); |
| 657 #endif | 658 #endif |
| 658 | 659 |
| 659 // Due to encoding limitation, we can only have 8K chunks. | 660 // Due to encoding limitation, we can only have 8K chunks. |
| 660 static const int kMaxNofChunks = 1 << kPageSizeBits; | 661 static const int kMaxNofChunks = 1 << kPageSizeBits; |
| 661 // If a chunk has at least 16 pages, the maximum heap size is about | 662 // If a chunk has at least 16 pages, the maximum heap size is about |
| 662 // 8K * 8K * 16 = 1G bytes. | 663 // 8K * 8K * 16 = 1G bytes. |
| 663 #ifdef V8_TARGET_ARCH_X64 | 664 #ifdef V8_TARGET_ARCH_X64 |
| 664 static const int kPagesPerChunk = 32; | 665 static const int kPagesPerChunk = 32; |
| 666 // On 64 bit the chunk table consists of 4 levels of 4096-entry tables. |
| 667 static const int kPagesPerChunkLog2 = 5; |
| 668 static const int kChunkTableLevels = 4; |
| 669 static const int kChunkTableBitsPerLevel = 12; |
| 665 #else | 670 #else |
| 666 static const int kPagesPerChunk = 16; | 671 static const int kPagesPerChunk = 16; |
| 672 // On 32 bit the chunk table consists of 2 levels of 256-entry tables. |
| 673 static const int kPagesPerChunkLog2 = 4; |
| 674 static const int kChunkTableLevels = 2; |
| 675 static const int kChunkTableBitsPerLevel = 8; |
| 667 #endif | 676 #endif |
| 668 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; | |
| 669 | 677 |
| 670 private: | 678 private: |
| 671 MemoryAllocator(); | 679 MemoryAllocator(); |
| 672 | 680 |
| 681 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; |
| 682 static const int kChunkSizeLog2 = kPagesPerChunkLog2 + kPageSizeBits; |
| 683 |
| 673 // Maximum space size in bytes. | 684 // Maximum space size in bytes. |
| 674 intptr_t capacity_; | 685 intptr_t capacity_; |
| 675 // Maximum subset of capacity_ that can be executable | 686 // Maximum subset of capacity_ that can be executable |
| 676 intptr_t capacity_executable_; | 687 intptr_t capacity_executable_; |
| 677 | 688 |
| 678 // Allocated space size in bytes. | 689 // Allocated space size in bytes. |
| 679 intptr_t size_; | 690 intptr_t size_; |
| 680 | 691 |
| 681 // Allocated executable space size in bytes. | 692 // Allocated executable space size in bytes. |
| 682 intptr_t size_executable_; | 693 intptr_t size_executable_; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 // subsequently torn down. | 1042 // subsequently torn down. |
| 1032 bool HasBeenSetup(); | 1043 bool HasBeenSetup(); |
| 1033 | 1044 |
| 1034 // Cleans up the space, frees all pages in this space except those belonging | 1045 // Cleans up the space, frees all pages in this space except those belonging |
| 1035 // to the initial chunk, uncommits addresses in the initial chunk. | 1046 // to the initial chunk, uncommits addresses in the initial chunk. |
| 1036 void TearDown(); | 1047 void TearDown(); |
| 1037 | 1048 |
| 1038 // Checks whether an object/address is in this space. | 1049 // Checks whether an object/address is in this space. |
| 1039 inline bool Contains(Address a); | 1050 inline bool Contains(Address a); |
| 1040 bool Contains(HeapObject* o) { return Contains(o->address()); } | 1051 bool Contains(HeapObject* o) { return Contains(o->address()); } |
| 1052 // Never crashes even if a is not a valid pointer. |
| 1053 inline bool SafeContains(Address a); |
| 1041 | 1054 |
| 1042 // Given an address occupied by a live object, return that object if it is | 1055 // Given an address occupied by a live object, return that object if it is |
| 1043 // in this space, or Failure::Exception() if it is not. The implementation | 1056 // in this space, or Failure::Exception() if it is not. The implementation |
| 1044 // iterates over objects in the page containing the address, the cost is | 1057 // iterates over objects in the page containing the address, the cost is |
| 1045 // linear in the number of objects in the page. It may be slow. | 1058 // linear in the number of objects in the page. It may be slow. |
| 1046 MUST_USE_RESULT MaybeObject* FindObject(Address addr); | 1059 MUST_USE_RESULT MaybeObject* FindObject(Address addr); |
| 1047 | 1060 |
| 1048 // Checks whether page is currently in use by this space. | 1061 // Checks whether page is currently in use by this space. |
| 1049 bool IsUsed(Page* page); | 1062 bool IsUsed(Page* page); |
| 1050 | 1063 |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2153 // A large object always starts at Page::kObjectStartOffset to a page. | 2166 // A large object always starts at Page::kObjectStartOffset to a page. |
| 2154 // Large objects do not move during garbage collections. | 2167 // Large objects do not move during garbage collections. |
| 2155 | 2168 |
| 2156 // A LargeObjectChunk holds exactly one large object page with exactly one | 2169 // A LargeObjectChunk holds exactly one large object page with exactly one |
| 2157 // large object. | 2170 // large object. |
| 2158 class LargeObjectChunk { | 2171 class LargeObjectChunk { |
| 2159 public: | 2172 public: |
| 2160 // Allocates a new LargeObjectChunk that contains a large object page | 2173 // Allocates a new LargeObjectChunk that contains a large object page |
| 2161 // (Page::kPageSize aligned) that has at least size_in_bytes (for a large | 2174 // (Page::kPageSize aligned) that has at least size_in_bytes (for a large |
| 2162 // object) bytes after the object area start of that page. | 2175 // object) bytes after the object area start of that page. |
| 2163 // The allocated chunk size is set in the output parameter chunk_size. | 2176 static LargeObjectChunk* New(int size_in_bytes, Executability executable); |
| 2164 static LargeObjectChunk* New(int size_in_bytes, | 2177 |
| 2165 size_t* chunk_size, | 2178 // Free the memory associated with the chunk. |
| 2166 Executability executable); | 2179 inline void Free(Executability executable); |
| 2167 | 2180 |
| 2168 // Interpret a raw address as a large object chunk. | 2181 // Interpret a raw address as a large object chunk. |
| 2169 static LargeObjectChunk* FromAddress(Address address) { | 2182 static LargeObjectChunk* FromAddress(Address address) { |
| 2170 return reinterpret_cast<LargeObjectChunk*>(address); | 2183 return reinterpret_cast<LargeObjectChunk*>(address); |
| 2171 } | 2184 } |
| 2172 | 2185 |
| 2173 // Returns the address of this chunk. | 2186 // Returns the address of this chunk. |
| 2174 Address address() { return reinterpret_cast<Address>(this); } | 2187 Address address() { return reinterpret_cast<Address>(this); } |
| 2175 | 2188 |
| 2176 // Accessors for the fields of the chunk. | 2189 // Accessors for the fields of the chunk. |
| 2177 LargeObjectChunk* next() { return next_; } | 2190 LargeObjectChunk* next() { return next_; } |
| 2178 void set_next(LargeObjectChunk* chunk) { next_ = chunk; } | 2191 void set_next(LargeObjectChunk* chunk) { next_ = chunk; } |
| 2192 size_t size() { return size_ & ~Page::kPageFlagMask; } |
| 2179 | 2193 |
| 2180 size_t size() { return size_ & ~Page::kPageFlagMask; } | 2194 // Compute the start address in the chunk. |
| 2181 void set_size(size_t size_in_bytes) { size_ = size_in_bytes; } | 2195 inline Address GetStartAddress(); |
| 2182 | 2196 |
| 2183 // Returns the object in this chunk. | 2197 // Returns the object in this chunk. |
| 2184 inline HeapObject* GetObject(); | 2198 HeapObject* GetObject() { return HeapObject::FromAddress(GetStartAddress()); } |
| 2185 | 2199 |
| 2186 // Given a requested size returns the physical size of a chunk to be | 2200 // Given a requested size returns the physical size of a chunk to be |
| 2187 // allocated. | 2201 // allocated. |
| 2188 static int ChunkSizeFor(int size_in_bytes); | 2202 static int ChunkSizeFor(int size_in_bytes); |
| 2189 | 2203 |
| 2190 // Given a chunk size, returns the object size it can accommodate. Used by | 2204 // Given a chunk size, returns the object size it can accommodate. Used by |
| 2191 // LargeObjectSpace::Available. | 2205 // LargeObjectSpace::Available. |
| 2192 static intptr_t ObjectSizeFor(intptr_t chunk_size) { | 2206 static intptr_t ObjectSizeFor(intptr_t chunk_size) { |
| 2193 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; | 2207 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; |
| 2194 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; | 2208 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; |
| 2195 } | 2209 } |
| 2196 | 2210 |
| 2197 private: | 2211 private: |
| 2198 // A pointer to the next large object chunk in the space or NULL. | 2212 // A pointer to the next large object chunk in the space or NULL. |
| 2199 LargeObjectChunk* next_; | 2213 LargeObjectChunk* next_; |
| 2200 | 2214 |
| 2201 // The size of this chunk. | 2215 // The total size of this chunk. |
| 2202 size_t size_; | 2216 size_t size_; |
| 2203 | 2217 |
| 2204 public: | 2218 public: |
| 2205 TRACK_MEMORY("LargeObjectChunk") | 2219 TRACK_MEMORY("LargeObjectChunk") |
| 2206 }; | 2220 }; |
| 2207 | 2221 |
| 2208 | 2222 |
| 2209 class LargeObjectSpace : public Space { | 2223 class LargeObjectSpace : public Space { |
| 2210 public: | 2224 public: |
| 2211 LargeObjectSpace(Heap* heap, AllocationSpace id); | 2225 LargeObjectSpace(Heap* heap, AllocationSpace id); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 } | 2343 } |
| 2330 // Must be small, since an iteration is used for lookup. | 2344 // Must be small, since an iteration is used for lookup. |
| 2331 static const int kMaxComments = 64; | 2345 static const int kMaxComments = 64; |
| 2332 }; | 2346 }; |
| 2333 #endif | 2347 #endif |
| 2334 | 2348 |
| 2335 | 2349 |
| 2336 } } // namespace v8::internal | 2350 } } // namespace v8::internal |
| 2337 | 2351 |
| 2338 #endif // V8_SPACES_H_ | 2352 #endif // V8_SPACES_H_ |
| OLD | NEW |