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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return true; | 288 return true; |
289 } | 289 } |
290 }; | 290 }; |
291 | 291 |
292 | 292 |
293 class SkipList; | 293 class SkipList; |
294 class SlotsBuffer; | 294 class SlotsBuffer; |
295 | 295 |
296 // MemoryChunk represents a memory region owned by a specific space. | 296 // MemoryChunk represents a memory region owned by a specific space. |
297 // It is divided into the header and the body. Chunk start is always | 297 // It is divided into the header and the body. Chunk start is always |
298 // 1MB aligned. Start of the body is aligned so it can accomodate | 298 // 1MB aligned. Start of the body is aligned so it can accommodate |
299 // any heap object. | 299 // any heap object. |
300 class MemoryChunk { | 300 class MemoryChunk { |
301 public: | 301 public: |
302 // Only works if the pointer is in the first kPageSize of the MemoryChunk. | 302 // Only works if the pointer is in the first kPageSize of the MemoryChunk. |
303 static MemoryChunk* FromAddress(Address a) { | 303 static MemoryChunk* FromAddress(Address a) { |
304 return reinterpret_cast<MemoryChunk*>(OffsetFrom(a) & ~kAlignmentMask); | 304 return reinterpret_cast<MemoryChunk*>(OffsetFrom(a) & ~kAlignmentMask); |
305 } | 305 } |
306 | 306 |
307 // Only works for addresses in pointer spaces, not data or code spaces. | 307 // Only works for addresses in pointer spaces, not data or code spaces. |
308 static inline MemoryChunk* FromAnyPointerAddress(Address addr); | 308 static inline MemoryChunk* FromAnyPointerAddress(Address addr); |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 #ifdef DEBUG | 1174 #ifdef DEBUG |
1175 bool VerifyPagedAllocation() { | 1175 bool VerifyPagedAllocation() { |
1176 return (Page::FromAllocationTop(top) == Page::FromAllocationTop(limit)) | 1176 return (Page::FromAllocationTop(top) == Page::FromAllocationTop(limit)) |
1177 && (top <= limit); | 1177 && (top <= limit); |
1178 } | 1178 } |
1179 #endif | 1179 #endif |
1180 }; | 1180 }; |
1181 | 1181 |
1182 | 1182 |
1183 // An abstraction of the accounting statistics of a page-structured space. | 1183 // An abstraction of the accounting statistics of a page-structured space. |
1184 // The 'capacity' of a space is the number of object-area bytes (ie, not | 1184 // The 'capacity' of a space is the number of object-area bytes (i.e., not |
1185 // including page bookkeeping structures) currently in the space. The 'size' | 1185 // including page bookkeeping structures) currently in the space. The 'size' |
1186 // of a space is the number of allocated bytes, the 'waste' in the space is | 1186 // of a space is the number of allocated bytes, the 'waste' in the space is |
1187 // the number of bytes that are not allocated and not available to | 1187 // the number of bytes that are not allocated and not available to |
1188 // allocation without reorganizing the space via a GC (eg, small blocks due | 1188 // allocation without reorganizing the space via a GC (e.g. small blocks due |
1189 // to internal fragmentation, top of page areas in map space), and the bytes | 1189 // to internal fragmentation, top of page areas in map space), and the bytes |
1190 // 'available' is the number of unallocated bytes that are not waste. The | 1190 // 'available' is the number of unallocated bytes that are not waste. The |
1191 // capacity is the sum of size, waste, and available. | 1191 // capacity is the sum of size, waste, and available. |
1192 // | 1192 // |
1193 // The stats are only set by functions that ensure they stay balanced. These | 1193 // The stats are only set by functions that ensure they stay balanced. These |
1194 // functions increase or decrease one of the non-capacity stats in | 1194 // functions increase or decrease one of the non-capacity stats in |
1195 // conjunction with capacity, or else they always balance increases and | 1195 // conjunction with capacity, or else they always balance increases and |
1196 // decreases to the non-capacity stats. | 1196 // decreases to the non-capacity stats. |
1197 class AllocationStats BASE_EMBEDDED { | 1197 class AllocationStats BASE_EMBEDDED { |
1198 public: | 1198 public: |
1199 AllocationStats() { Clear(); } | 1199 AllocationStats() { Clear(); } |
1200 | 1200 |
1201 // Zero out all the allocation statistics (ie, no capacity). | 1201 // Zero out all the allocation statistics (i.e., no capacity). |
1202 void Clear() { | 1202 void Clear() { |
1203 capacity_ = 0; | 1203 capacity_ = 0; |
1204 size_ = 0; | 1204 size_ = 0; |
1205 waste_ = 0; | 1205 waste_ = 0; |
1206 } | 1206 } |
1207 | 1207 |
1208 void ClearSizeWaste() { | 1208 void ClearSizeWaste() { |
1209 size_ = capacity_; | 1209 size_ = capacity_; |
1210 waste_ = 0; | 1210 waste_ = 0; |
1211 } | 1211 } |
1212 | 1212 |
1213 // Reset the allocation statistics (ie, available = capacity with no | 1213 // Reset the allocation statistics (i.e., available = capacity with no |
1214 // wasted or allocated bytes). | 1214 // wasted or allocated bytes). |
1215 void Reset() { | 1215 void Reset() { |
1216 size_ = 0; | 1216 size_ = 0; |
1217 waste_ = 0; | 1217 waste_ = 0; |
1218 } | 1218 } |
1219 | 1219 |
1220 // Accessors for the allocation statistics. | 1220 // Accessors for the allocation statistics. |
1221 intptr_t Capacity() { return capacity_; } | 1221 intptr_t Capacity() { return capacity_; } |
1222 intptr_t Size() { return size_; } | 1222 intptr_t Size() { return size_; } |
1223 intptr_t Waste() { return waste_; } | 1223 intptr_t Waste() { return waste_; } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 // Clear the free list. | 1334 // Clear the free list. |
1335 void Reset(); | 1335 void Reset(); |
1336 | 1336 |
1337 // Return the number of bytes available on the free list. | 1337 // Return the number of bytes available on the free list. |
1338 intptr_t available() { return available_; } | 1338 intptr_t available() { return available_; } |
1339 | 1339 |
1340 // Place a node on the free list. The block of size 'size_in_bytes' | 1340 // Place a node on the free list. The block of size 'size_in_bytes' |
1341 // starting at 'start' is placed on the free list. The return value is the | 1341 // starting at 'start' is placed on the free list. The return value is the |
1342 // number of bytes that have been lost due to internal fragmentation by | 1342 // number of bytes that have been lost due to internal fragmentation by |
1343 // freeing the block. Bookkeeping information will be written to the block, | 1343 // freeing the block. Bookkeeping information will be written to the block, |
1344 // ie, its contents will be destroyed. The start address should be word | 1344 // i.e., its contents will be destroyed. The start address should be word |
1345 // aligned, and the size should be a non-zero multiple of the word size. | 1345 // aligned, and the size should be a non-zero multiple of the word size. |
1346 int Free(Address start, int size_in_bytes); | 1346 int Free(Address start, int size_in_bytes); |
1347 | 1347 |
1348 // Allocate a block of size 'size_in_bytes' from the free list. The block | 1348 // Allocate a block of size 'size_in_bytes' from the free list. The block |
1349 // is unitialized. A failure is returned if no block is available. The | 1349 // is unitialized. A failure is returned if no block is available. The |
1350 // number of bytes lost to fragmentation is returned in the output parameter | 1350 // number of bytes lost to fragmentation is returned in the output parameter |
1351 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. | 1351 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. |
1352 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); | 1352 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); |
1353 | 1353 |
1354 #ifdef DEBUG | 1354 #ifdef DEBUG |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2643 } | 2643 } |
2644 // Must be small, since an iteration is used for lookup. | 2644 // Must be small, since an iteration is used for lookup. |
2645 static const int kMaxComments = 64; | 2645 static const int kMaxComments = 64; |
2646 }; | 2646 }; |
2647 #endif | 2647 #endif |
2648 | 2648 |
2649 | 2649 |
2650 } } // namespace v8::internal | 2650 } } // namespace v8::internal |
2651 | 2651 |
2652 #endif // V8_SPACES_H_ | 2652 #endif // V8_SPACES_H_ |
OLD | NEW |