| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 // Identity used in error reporting. | 373 // Identity used in error reporting. |
| 374 AllocationSpace identity() { return id_; } | 374 AllocationSpace identity() { return id_; } |
| 375 | 375 |
| 376 // Returns allocated size. | 376 // Returns allocated size. |
| 377 virtual intptr_t Size() = 0; | 377 virtual intptr_t Size() = 0; |
| 378 | 378 |
| 379 // Returns size of objects. Can differ from the allocated size | 379 // Returns size of objects. Can differ from the allocated size |
| 380 // (e.g. see LargeObjectSpace). | 380 // (e.g. see LargeObjectSpace). |
| 381 virtual intptr_t SizeOfObjects() { return Size(); } | 381 virtual intptr_t SizeOfObjects() { return Size(); } |
| 382 | 382 |
| 383 #ifdef ENABLE_HEAP_PROTECTION | |
| 384 // Protect/unprotect the space by marking it read-only/writable. | |
| 385 virtual void Protect() = 0; | |
| 386 virtual void Unprotect() = 0; | |
| 387 #endif | |
| 388 | |
| 389 #ifdef DEBUG | 383 #ifdef DEBUG |
| 390 virtual void Print() = 0; | 384 virtual void Print() = 0; |
| 391 #endif | 385 #endif |
| 392 | 386 |
| 393 // After calling this we can allocate a certain number of bytes using only | 387 // After calling this we can allocate a certain number of bytes using only |
| 394 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) | 388 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) |
| 395 // without using freelists or causing a GC. This is used by partial | 389 // without using freelists or causing a GC. This is used by partial |
| 396 // snapshots. It returns true of space was reserved or false if a GC is | 390 // snapshots. It returns true of space was reserved or false if a GC is |
| 397 // needed. For paged spaces the space requested must include the space wasted | 391 // needed. For paged spaces the space requested must include the space wasted |
| 398 // at the end of each when allocating linearly. | 392 // at the end of each when allocating linearly. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 628 |
| 635 // Relinks list of pages owned by space to make it chunk-ordered. | 629 // Relinks list of pages owned by space to make it chunk-ordered. |
| 636 // Returns new first and last pages of space. | 630 // Returns new first and last pages of space. |
| 637 // Also returns last page in relinked list which has WasInUsedBeforeMC | 631 // Also returns last page in relinked list which has WasInUsedBeforeMC |
| 638 // flag set. | 632 // flag set. |
| 639 void RelinkPageListInChunkOrder(PagedSpace* space, | 633 void RelinkPageListInChunkOrder(PagedSpace* space, |
| 640 Page** first_page, | 634 Page** first_page, |
| 641 Page** last_page, | 635 Page** last_page, |
| 642 Page** last_page_in_use); | 636 Page** last_page_in_use); |
| 643 | 637 |
| 644 #ifdef ENABLE_HEAP_PROTECTION | |
| 645 // Protect/unprotect a block of memory by marking it read-only/writable. | |
| 646 inline void Protect(Address start, size_t size); | |
| 647 inline void Unprotect(Address start, size_t size, | |
| 648 Executability executable); | |
| 649 | |
| 650 // Protect/unprotect a chunk given a page in the chunk. | |
| 651 inline void ProtectChunkFromPage(Page* page); | |
| 652 inline void UnprotectChunkFromPage(Page* page); | |
| 653 #endif | |
| 654 | |
| 655 #ifdef DEBUG | 638 #ifdef DEBUG |
| 656 // Reports statistic info of the space. | 639 // Reports statistic info of the space. |
| 657 void ReportStatistics(); | 640 void ReportStatistics(); |
| 658 #endif | 641 #endif |
| 659 | 642 |
| 660 // Due to encoding limitation, we can only have 8K chunks. | 643 // Due to encoding limitation, we can only have 8K chunks. |
| 661 static const int kMaxNofChunks = 1 << kPageSizeBits; | 644 static const int kMaxNofChunks = 1 << kPageSizeBits; |
| 662 // If a chunk has at least 16 pages, the maximum heap size is about | 645 // If a chunk has at least 16 pages, the maximum heap size is about |
| 663 // 8K * 8K * 16 = 1G bytes. | 646 // 8K * 8K * 16 = 1G bytes. |
| 664 #ifdef V8_TARGET_ARCH_X64 | 647 #ifdef V8_TARGET_ARCH_X64 |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 // Updates the allocation pointer to the relocation top after a mark-compact | 1133 // Updates the allocation pointer to the relocation top after a mark-compact |
| 1151 // collection. | 1134 // collection. |
| 1152 virtual void MCCommitRelocationInfo() = 0; | 1135 virtual void MCCommitRelocationInfo() = 0; |
| 1153 | 1136 |
| 1154 // Releases half of unused pages. | 1137 // Releases half of unused pages. |
| 1155 void Shrink(); | 1138 void Shrink(); |
| 1156 | 1139 |
| 1157 // Ensures that the capacity is at least 'capacity'. Returns false on failure. | 1140 // Ensures that the capacity is at least 'capacity'. Returns false on failure. |
| 1158 bool EnsureCapacity(int capacity); | 1141 bool EnsureCapacity(int capacity); |
| 1159 | 1142 |
| 1160 #ifdef ENABLE_HEAP_PROTECTION | |
| 1161 // Protect/unprotect the space by marking it read-only/writable. | |
| 1162 void Protect(); | |
| 1163 void Unprotect(); | |
| 1164 #endif | |
| 1165 | |
| 1166 #ifdef DEBUG | 1143 #ifdef DEBUG |
| 1167 // Print meta info and objects in this space. | 1144 // Print meta info and objects in this space. |
| 1168 virtual void Print(); | 1145 virtual void Print(); |
| 1169 | 1146 |
| 1170 // Verify integrity of this space. | 1147 // Verify integrity of this space. |
| 1171 virtual void Verify(ObjectVisitor* visitor); | 1148 virtual void Verify(ObjectVisitor* visitor); |
| 1172 | 1149 |
| 1173 // Overridden by subclasses to verify space-specific object | 1150 // Overridden by subclasses to verify space-specific object |
| 1174 // properties (e.g., only maps or free-list nodes are in map space). | 1151 // properties (e.g., only maps or free-list nodes are in map space). |
| 1175 virtual void VerifyObject(HeapObject* obj) {} | 1152 virtual void VerifyObject(HeapObject* obj) {} |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 #endif | 1240 #endif |
| 1264 private: | 1241 private: |
| 1265 | 1242 |
| 1266 // Returns a pointer to the page of the relocation pointer. | 1243 // Returns a pointer to the page of the relocation pointer. |
| 1267 Page* MCRelocationTopPage() { return TopPageOf(mc_forwarding_info_); } | 1244 Page* MCRelocationTopPage() { return TopPageOf(mc_forwarding_info_); } |
| 1268 | 1245 |
| 1269 friend class PageIterator; | 1246 friend class PageIterator; |
| 1270 }; | 1247 }; |
| 1271 | 1248 |
| 1272 | 1249 |
| 1273 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 1274 class NumberAndSizeInfo BASE_EMBEDDED { | 1250 class NumberAndSizeInfo BASE_EMBEDDED { |
| 1275 public: | 1251 public: |
| 1276 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 1252 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
| 1277 | 1253 |
| 1278 int number() const { return number_; } | 1254 int number() const { return number_; } |
| 1279 void increment_number(int num) { number_ += num; } | 1255 void increment_number(int num) { number_ += num; } |
| 1280 | 1256 |
| 1281 int bytes() const { return bytes_; } | 1257 int bytes() const { return bytes_; } |
| 1282 void increment_bytes(int size) { bytes_ += size; } | 1258 void increment_bytes(int size) { bytes_ += size; } |
| 1283 | 1259 |
| 1284 void clear() { | 1260 void clear() { |
| 1285 number_ = 0; | 1261 number_ = 0; |
| 1286 bytes_ = 0; | 1262 bytes_ = 0; |
| 1287 } | 1263 } |
| 1288 | 1264 |
| 1289 private: | 1265 private: |
| 1290 int number_; | 1266 int number_; |
| 1291 int bytes_; | 1267 int bytes_; |
| 1292 }; | 1268 }; |
| 1293 | 1269 |
| 1294 | 1270 |
| 1295 // HistogramInfo class for recording a single "bar" of a histogram. This | 1271 // HistogramInfo class for recording a single "bar" of a histogram. This |
| 1296 // class is used for collecting statistics to print to stdout (when compiled | 1272 // class is used for collecting statistics to print to the log file. |
| 1297 // with DEBUG) or to the log file (when compiled with | |
| 1298 // ENABLE_LOGGING_AND_PROFILING). | |
| 1299 class HistogramInfo: public NumberAndSizeInfo { | 1273 class HistogramInfo: public NumberAndSizeInfo { |
| 1300 public: | 1274 public: |
| 1301 HistogramInfo() : NumberAndSizeInfo() {} | 1275 HistogramInfo() : NumberAndSizeInfo() {} |
| 1302 | 1276 |
| 1303 const char* name() { return name_; } | 1277 const char* name() { return name_; } |
| 1304 void set_name(const char* name) { name_ = name; } | 1278 void set_name(const char* name) { name_ = name; } |
| 1305 | 1279 |
| 1306 private: | 1280 private: |
| 1307 const char* name_; | 1281 const char* name_; |
| 1308 }; | 1282 }; |
| 1309 #endif | |
| 1310 | 1283 |
| 1311 | 1284 |
| 1312 // ----------------------------------------------------------------------------- | 1285 // ----------------------------------------------------------------------------- |
| 1313 // SemiSpace in young generation | 1286 // SemiSpace in young generation |
| 1314 // | 1287 // |
| 1315 // A semispace is a contiguous chunk of memory. The mark-compact collector | 1288 // A semispace is a contiguous chunk of memory. The mark-compact collector |
| 1316 // uses the memory in the from space as a marking stack when tracing live | 1289 // uses the memory in the from space as a marking stack when tracing live |
| 1317 // objects. | 1290 // objects. |
| 1318 | 1291 |
| 1319 class SemiSpace : public Space { | 1292 class SemiSpace : public Space { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 | 1358 |
| 1386 virtual bool ReserveSpace(int bytes) { | 1359 virtual bool ReserveSpace(int bytes) { |
| 1387 UNREACHABLE(); | 1360 UNREACHABLE(); |
| 1388 return false; | 1361 return false; |
| 1389 } | 1362 } |
| 1390 | 1363 |
| 1391 bool is_committed() { return committed_; } | 1364 bool is_committed() { return committed_; } |
| 1392 bool Commit(); | 1365 bool Commit(); |
| 1393 bool Uncommit(); | 1366 bool Uncommit(); |
| 1394 | 1367 |
| 1395 #ifdef ENABLE_HEAP_PROTECTION | |
| 1396 // Protect/unprotect the space by marking it read-only/writable. | |
| 1397 virtual void Protect() {} | |
| 1398 virtual void Unprotect() {} | |
| 1399 #endif | |
| 1400 | |
| 1401 #ifdef DEBUG | 1368 #ifdef DEBUG |
| 1402 virtual void Print(); | 1369 virtual void Print(); |
| 1403 virtual void Verify(); | 1370 virtual void Verify(); |
| 1404 #endif | 1371 #endif |
| 1405 | 1372 |
| 1406 // Returns the current capacity of the semi space. | 1373 // Returns the current capacity of the semi space. |
| 1407 int Capacity() { return capacity_; } | 1374 int Capacity() { return capacity_; } |
| 1408 | 1375 |
| 1409 // Returns the maximum capacity of the semi space. | 1376 // Returns the maximum capacity of the semi space. |
| 1410 int MaximumCapacity() { return maximum_capacity_; } | 1377 int MaximumCapacity() { return maximum_capacity_; } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 bool ToSpaceContains(Address a) { return to_space_.Contains(a); } | 1588 bool ToSpaceContains(Address a) { return to_space_.Contains(a); } |
| 1622 bool FromSpaceContains(Address a) { return from_space_.Contains(a); } | 1589 bool FromSpaceContains(Address a) { return from_space_.Contains(a); } |
| 1623 | 1590 |
| 1624 virtual bool ReserveSpace(int bytes); | 1591 virtual bool ReserveSpace(int bytes); |
| 1625 | 1592 |
| 1626 // Resizes a sequential string which must be the most recent thing that was | 1593 // Resizes a sequential string which must be the most recent thing that was |
| 1627 // allocated in new space. | 1594 // allocated in new space. |
| 1628 template <typename StringType> | 1595 template <typename StringType> |
| 1629 inline void ShrinkStringAtAllocationBoundary(String* string, int len); | 1596 inline void ShrinkStringAtAllocationBoundary(String* string, int len); |
| 1630 | 1597 |
| 1631 #ifdef ENABLE_HEAP_PROTECTION | |
| 1632 // Protect/unprotect the space by marking it read-only/writable. | |
| 1633 virtual void Protect(); | |
| 1634 virtual void Unprotect(); | |
| 1635 #endif | |
| 1636 | |
| 1637 #ifdef DEBUG | 1598 #ifdef DEBUG |
| 1638 // Verify the active semispace. | 1599 // Verify the active semispace. |
| 1639 virtual void Verify(); | 1600 virtual void Verify(); |
| 1640 // Print the active semispace. | 1601 // Print the active semispace. |
| 1641 virtual void Print() { to_space_.Print(); } | 1602 virtual void Print() { to_space_.Print(); } |
| 1642 #endif | 1603 #endif |
| 1643 | 1604 |
| 1644 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 1645 // Iterates the active semispace to collect statistics. | 1605 // Iterates the active semispace to collect statistics. |
| 1646 void CollectStatistics(); | 1606 void CollectStatistics(); |
| 1647 // Reports previously collected statistics of the active semispace. | 1607 // Reports previously collected statistics of the active semispace. |
| 1648 void ReportStatistics(); | 1608 void ReportStatistics(); |
| 1649 // Clears previously collected statistics. | 1609 // Clears previously collected statistics. |
| 1650 void ClearHistograms(); | 1610 void ClearHistograms(); |
| 1651 | 1611 |
| 1652 // Record the allocation or promotion of a heap object. Note that we don't | 1612 // Record the allocation or promotion of a heap object. Note that we don't |
| 1653 // record every single allocation, but only those that happen in the | 1613 // record every single allocation, but only those that happen in the |
| 1654 // to space during a scavenge GC. | 1614 // to space during a scavenge GC. |
| 1655 void RecordAllocation(HeapObject* obj); | 1615 void RecordAllocation(HeapObject* obj); |
| 1656 void RecordPromotion(HeapObject* obj); | 1616 void RecordPromotion(HeapObject* obj); |
| 1657 #endif | |
| 1658 | 1617 |
| 1659 // Return whether the operation succeded. | 1618 // Return whether the operation succeded. |
| 1660 bool CommitFromSpaceIfNeeded() { | 1619 bool CommitFromSpaceIfNeeded() { |
| 1661 if (from_space_.is_committed()) return true; | 1620 if (from_space_.is_committed()) return true; |
| 1662 return from_space_.Commit(); | 1621 return from_space_.Commit(); |
| 1663 } | 1622 } |
| 1664 | 1623 |
| 1665 bool UncommitFromSpace() { | 1624 bool UncommitFromSpace() { |
| 1666 if (!from_space_.is_committed()) return true; | 1625 if (!from_space_.is_committed()) return true; |
| 1667 return from_space_.Uncommit(); | 1626 return from_space_.Uncommit(); |
| 1668 } | 1627 } |
| 1669 | 1628 |
| 1670 private: | 1629 private: |
| 1671 // The semispaces. | 1630 // The semispaces. |
| 1672 SemiSpace to_space_; | 1631 SemiSpace to_space_; |
| 1673 SemiSpace from_space_; | 1632 SemiSpace from_space_; |
| 1674 | 1633 |
| 1675 // Start address and bit mask for containment testing. | 1634 // Start address and bit mask for containment testing. |
| 1676 Address start_; | 1635 Address start_; |
| 1677 uintptr_t address_mask_; | 1636 uintptr_t address_mask_; |
| 1678 uintptr_t object_mask_; | 1637 uintptr_t object_mask_; |
| 1679 uintptr_t object_expected_; | 1638 uintptr_t object_expected_; |
| 1680 | 1639 |
| 1681 // Allocation pointer and limit for normal allocation and allocation during | 1640 // Allocation pointer and limit for normal allocation and allocation during |
| 1682 // mark-compact collection. | 1641 // mark-compact collection. |
| 1683 AllocationInfo allocation_info_; | 1642 AllocationInfo allocation_info_; |
| 1684 AllocationInfo mc_forwarding_info_; | 1643 AllocationInfo mc_forwarding_info_; |
| 1685 | 1644 |
| 1686 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 1687 HistogramInfo* allocated_histogram_; | 1645 HistogramInfo* allocated_histogram_; |
| 1688 HistogramInfo* promoted_histogram_; | 1646 HistogramInfo* promoted_histogram_; |
| 1689 #endif | |
| 1690 | 1647 |
| 1691 // Implementation of AllocateRaw and MCAllocateRaw. | 1648 // Implementation of AllocateRaw and MCAllocateRaw. |
| 1692 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal( | 1649 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal( |
| 1693 int size_in_bytes, | 1650 int size_in_bytes, |
| 1694 AllocationInfo* alloc_info); | 1651 AllocationInfo* alloc_info); |
| 1695 | 1652 |
| 1696 friend class SemiSpaceIterator; | 1653 friend class SemiSpaceIterator; |
| 1697 | 1654 |
| 1698 public: | 1655 public: |
| 1699 TRACK_MEMORY("NewSpace") | 1656 TRACK_MEMORY("NewSpace") |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2289 bool Contains(HeapObject* obj); | 2246 bool Contains(HeapObject* obj); |
| 2290 | 2247 |
| 2291 // Checks whether the space is empty. | 2248 // Checks whether the space is empty. |
| 2292 bool IsEmpty() { return first_chunk_ == NULL; } | 2249 bool IsEmpty() { return first_chunk_ == NULL; } |
| 2293 | 2250 |
| 2294 // See the comments for ReserveSpace in the Space class. This has to be | 2251 // See the comments for ReserveSpace in the Space class. This has to be |
| 2295 // called after ReserveSpace has been called on the paged spaces, since they | 2252 // called after ReserveSpace has been called on the paged spaces, since they |
| 2296 // may use some memory, leaving less for large objects. | 2253 // may use some memory, leaving less for large objects. |
| 2297 virtual bool ReserveSpace(int bytes); | 2254 virtual bool ReserveSpace(int bytes); |
| 2298 | 2255 |
| 2299 #ifdef ENABLE_HEAP_PROTECTION | |
| 2300 // Protect/unprotect the space by marking it read-only/writable. | |
| 2301 void Protect(); | |
| 2302 void Unprotect(); | |
| 2303 #endif | |
| 2304 | |
| 2305 #ifdef DEBUG | 2256 #ifdef DEBUG |
| 2306 virtual void Verify(); | 2257 virtual void Verify(); |
| 2307 virtual void Print(); | 2258 virtual void Print(); |
| 2308 void ReportStatistics(); | 2259 void ReportStatistics(); |
| 2309 void CollectCodeStatistics(); | 2260 void CollectCodeStatistics(); |
| 2310 #endif | 2261 #endif |
| 2311 // Checks whether an address is in the object area in this space. It | 2262 // Checks whether an address is in the object area in this space. It |
| 2312 // iterates all objects in the space. May be slow. | 2263 // iterates all objects in the space. May be slow. |
| 2313 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } | 2264 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } |
| 2314 | 2265 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 } | 2311 } |
| 2361 // Must be small, since an iteration is used for lookup. | 2312 // Must be small, since an iteration is used for lookup. |
| 2362 static const int kMaxComments = 64; | 2313 static const int kMaxComments = 64; |
| 2363 }; | 2314 }; |
| 2364 #endif | 2315 #endif |
| 2365 | 2316 |
| 2366 | 2317 |
| 2367 } } // namespace v8::internal | 2318 } } // namespace v8::internal |
| 2368 | 2319 |
| 2369 #endif // V8_SPACES_H_ | 2320 #endif // V8_SPACES_H_ |
| OLD | NEW |