| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 // Does the space need executable memory? | 296 // Does the space need executable memory? |
| 297 Executability executable() { return executable_; } | 297 Executability executable() { return executable_; } |
| 298 | 298 |
| 299 // Identity used in error reporting. | 299 // Identity used in error reporting. |
| 300 AllocationSpace identity() { return id_; } | 300 AllocationSpace identity() { return id_; } |
| 301 | 301 |
| 302 virtual int Size() = 0; | 302 virtual int Size() = 0; |
| 303 | 303 |
| 304 #ifdef DEBUG | 304 #ifdef DEBUG |
| 305 virtual void Verify() = 0; | |
| 306 virtual void Print() = 0; | 305 virtual void Print() = 0; |
| 307 #endif | 306 #endif |
| 308 | 307 |
| 309 private: | 308 private: |
| 310 AllocationSpace id_; | 309 AllocationSpace id_; |
| 311 Executability executable_; | 310 Executability executable_; |
| 312 }; | 311 }; |
| 313 | 312 |
| 314 | 313 |
| 315 // ---------------------------------------------------------------------------- | 314 // ---------------------------------------------------------------------------- |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 #ifdef ENABLE_HEAP_PROTECTION | 828 #ifdef ENABLE_HEAP_PROTECTION |
| 830 // Protect/unprotect the space by marking it read-only/writable. | 829 // Protect/unprotect the space by marking it read-only/writable. |
| 831 void Protect(); | 830 void Protect(); |
| 832 void Unprotect(); | 831 void Unprotect(); |
| 833 #endif | 832 #endif |
| 834 | 833 |
| 835 #ifdef DEBUG | 834 #ifdef DEBUG |
| 836 // Print meta info and objects in this space. | 835 // Print meta info and objects in this space. |
| 837 virtual void Print(); | 836 virtual void Print(); |
| 838 | 837 |
| 838 // Verify integrity of this space. |
| 839 virtual void Verify(ObjectVisitor* visitor); |
| 840 |
| 841 // Overridden by subclasses to verify space-specific object |
| 842 // properties (e.g., only maps or free-list nodes are in map space). |
| 843 virtual void VerifyObject(HeapObject* obj) {} |
| 844 |
| 839 // Report code object related statistics | 845 // Report code object related statistics |
| 840 void CollectCodeStatistics(); | 846 void CollectCodeStatistics(); |
| 841 static void ReportCodeStatistics(); | 847 static void ReportCodeStatistics(); |
| 842 static void ResetCodeStatistics(); | 848 static void ResetCodeStatistics(); |
| 843 #endif | 849 #endif |
| 844 | 850 |
| 845 protected: | 851 protected: |
| 846 // Maximum capacity of this space. | 852 // Maximum capacity of this space. |
| 847 int max_capacity_; | 853 int max_capacity_; |
| 848 | 854 |
| 849 // Accounting information for this space. | 855 // Accounting information for this space. |
| 850 AllocationStats accounting_stats_; | 856 AllocationStats accounting_stats_; |
| 851 | 857 |
| 852 // The first page in this space. | 858 // The first page in this space. |
| 853 Page* first_page_; | 859 Page* first_page_; |
| 854 | 860 |
| 855 // The last page in this space. Initially set in Setup, updated in | 861 // The last page in this space. Initially set in Setup, updated in |
| 856 // Expand and Shrink. | 862 // Expand and Shrink. |
| 857 Page* last_page_; | 863 Page* last_page_; |
| 858 | 864 |
| 859 // Normal allocation information. | 865 // Normal allocation information. |
| 860 AllocationInfo allocation_info_; | 866 AllocationInfo allocation_info_; |
| 861 | 867 |
| 862 // Relocation information during mark-compact collections. | 868 // Relocation information during mark-compact collections. |
| 863 AllocationInfo mc_forwarding_info_; | 869 AllocationInfo mc_forwarding_info_; |
| 864 | 870 |
| 871 // Bytes of each page that cannot be allocated. Possibly non-zero |
| 872 // for pages in spaces with only fixed-size objects. Always zero |
| 873 // for pages in spaces with variable sized objects (those pages are |
| 874 // padded with free-list nodes). |
| 875 int page_extra_; |
| 876 |
| 865 // Sets allocation pointer to a page bottom. | 877 // Sets allocation pointer to a page bottom. |
| 866 static void SetAllocationInfo(AllocationInfo* alloc_info, Page* p); | 878 static void SetAllocationInfo(AllocationInfo* alloc_info, Page* p); |
| 867 | 879 |
| 868 // Returns the top page specified by an allocation info structure. | 880 // Returns the top page specified by an allocation info structure. |
| 869 static Page* TopPageOf(AllocationInfo alloc_info) { | 881 static Page* TopPageOf(AllocationInfo alloc_info) { |
| 870 return Page::FromAllocationTop(alloc_info.limit); | 882 return Page::FromAllocationTop(alloc_info.limit); |
| 871 } | 883 } |
| 872 | 884 |
| 873 // Expands the space by allocating a fixed number of pages. Returns false if | 885 // Expands the space by allocating a fixed number of pages. Returns false if |
| 874 // it cannot allocate requested number of pages from OS. Newly allocated | 886 // it cannot allocate requested number of pages from OS. Newly allocated |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 // Old object space (excluding map objects) | 1444 // Old object space (excluding map objects) |
| 1433 | 1445 |
| 1434 class OldSpace : public PagedSpace { | 1446 class OldSpace : public PagedSpace { |
| 1435 public: | 1447 public: |
| 1436 // Creates an old space object with a given maximum capacity. | 1448 // Creates an old space object with a given maximum capacity. |
| 1437 // The constructor does not allocate pages from OS. | 1449 // The constructor does not allocate pages from OS. |
| 1438 explicit OldSpace(int max_capacity, | 1450 explicit OldSpace(int max_capacity, |
| 1439 AllocationSpace id, | 1451 AllocationSpace id, |
| 1440 Executability executable) | 1452 Executability executable) |
| 1441 : PagedSpace(max_capacity, id, executable), free_list_(id) { | 1453 : PagedSpace(max_capacity, id, executable), free_list_(id) { |
| 1454 page_extra_ = 0; |
| 1442 } | 1455 } |
| 1443 | 1456 |
| 1444 // The bytes available on the free list (ie, not above the linear allocation | 1457 // The bytes available on the free list (ie, not above the linear allocation |
| 1445 // pointer). | 1458 // pointer). |
| 1446 int AvailableFree() { return free_list_.available(); } | 1459 int AvailableFree() { return free_list_.available(); } |
| 1447 | 1460 |
| 1448 // The top of allocation in a page in this space. Undefined if page is unused. | 1461 // The top of allocation in a page in this space. Undefined if page is unused. |
| 1449 virtual Address PageAllocationTop(Page* page) { | 1462 virtual Address PageAllocationTop(Page* page) { |
| 1450 return page == TopPageOf(allocation_info_) ? top() : page->ObjectAreaEnd(); | 1463 return page == TopPageOf(allocation_info_) ? top() : page->ObjectAreaEnd(); |
| 1451 } | 1464 } |
| 1452 | 1465 |
| 1453 // Give a block of memory to the space's free list. It might be added to | 1466 // Give a block of memory to the space's free list. It might be added to |
| 1454 // the free list or accounted as waste. | 1467 // the free list or accounted as waste. |
| 1455 void Free(Address start, int size_in_bytes) { | 1468 void Free(Address start, int size_in_bytes) { |
| 1456 int wasted_bytes = free_list_.Free(start, size_in_bytes); | 1469 int wasted_bytes = free_list_.Free(start, size_in_bytes); |
| 1457 accounting_stats_.DeallocateBytes(size_in_bytes); | 1470 accounting_stats_.DeallocateBytes(size_in_bytes); |
| 1458 accounting_stats_.WasteBytes(wasted_bytes); | 1471 accounting_stats_.WasteBytes(wasted_bytes); |
| 1459 } | 1472 } |
| 1460 | 1473 |
| 1461 // Prepare for full garbage collection. Resets the relocation pointer and | 1474 // Prepare for full garbage collection. Resets the relocation pointer and |
| 1462 // clears the free list. | 1475 // clears the free list. |
| 1463 virtual void PrepareForMarkCompact(bool will_compact); | 1476 virtual void PrepareForMarkCompact(bool will_compact); |
| 1464 | 1477 |
| 1465 // Updates the allocation pointer to the relocation top after a mark-compact | 1478 // Updates the allocation pointer to the relocation top after a mark-compact |
| 1466 // collection. | 1479 // collection. |
| 1467 virtual void MCCommitRelocationInfo(); | 1480 virtual void MCCommitRelocationInfo(); |
| 1468 | 1481 |
| 1469 #ifdef DEBUG | 1482 #ifdef DEBUG |
| 1470 // Verify integrity of this space. | |
| 1471 virtual void Verify(); | |
| 1472 | |
| 1473 // Reports statistics for the space | 1483 // Reports statistics for the space |
| 1474 void ReportStatistics(); | 1484 void ReportStatistics(); |
| 1475 // Dump the remembered sets in the space to stdout. | 1485 // Dump the remembered sets in the space to stdout. |
| 1476 void PrintRSet(); | 1486 void PrintRSet(); |
| 1477 #endif | 1487 #endif |
| 1478 | 1488 |
| 1479 protected: | 1489 protected: |
| 1480 // Virtual function in the superclass. Slow path of AllocateRaw. | 1490 // Virtual function in the superclass. Slow path of AllocateRaw. |
| 1481 HeapObject* SlowAllocateRaw(int size_in_bytes); | 1491 HeapObject* SlowAllocateRaw(int size_in_bytes); |
| 1482 | 1492 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1498 | 1508 |
| 1499 class FixedSpace : public PagedSpace { | 1509 class FixedSpace : public PagedSpace { |
| 1500 public: | 1510 public: |
| 1501 FixedSpace(int max_capacity, | 1511 FixedSpace(int max_capacity, |
| 1502 AllocationSpace id, | 1512 AllocationSpace id, |
| 1503 int object_size_in_bytes, | 1513 int object_size_in_bytes, |
| 1504 const char* name) | 1514 const char* name) |
| 1505 : PagedSpace(max_capacity, id, NOT_EXECUTABLE), | 1515 : PagedSpace(max_capacity, id, NOT_EXECUTABLE), |
| 1506 object_size_in_bytes_(object_size_in_bytes), | 1516 object_size_in_bytes_(object_size_in_bytes), |
| 1507 name_(name), | 1517 name_(name), |
| 1508 free_list_(id, object_size_in_bytes), | 1518 free_list_(id, object_size_in_bytes) { |
| 1509 page_extra_(Page::kObjectAreaSize % object_size_in_bytes) { } | 1519 page_extra_ = Page::kObjectAreaSize % object_size_in_bytes; |
| 1520 } |
| 1510 | 1521 |
| 1511 // The top of allocation in a page in this space. Undefined if page is unused. | 1522 // The top of allocation in a page in this space. Undefined if page is unused. |
| 1512 virtual Address PageAllocationTop(Page* page) { | 1523 virtual Address PageAllocationTop(Page* page) { |
| 1513 return page == TopPageOf(allocation_info_) ? top() | 1524 return page == TopPageOf(allocation_info_) ? top() |
| 1514 : page->ObjectAreaEnd() - page_extra_; | 1525 : page->ObjectAreaEnd() - page_extra_; |
| 1515 } | 1526 } |
| 1516 | 1527 |
| 1517 int object_size_in_bytes() { return object_size_in_bytes_; } | 1528 int object_size_in_bytes() { return object_size_in_bytes_; } |
| 1518 | 1529 |
| 1519 // Give a fixed sized block of memory to the space's free list. | 1530 // Give a fixed sized block of memory to the space's free list. |
| 1520 void Free(Address start) { | 1531 void Free(Address start) { |
| 1521 free_list_.Free(start); | 1532 free_list_.Free(start); |
| 1522 accounting_stats_.DeallocateBytes(Map::kSize); | 1533 accounting_stats_.DeallocateBytes(Map::kSize); |
| 1523 } | 1534 } |
| 1524 | 1535 |
| 1525 // Prepares for a mark-compact GC. | 1536 // Prepares for a mark-compact GC. |
| 1526 virtual void PrepareForMarkCompact(bool will_compact); | 1537 virtual void PrepareForMarkCompact(bool will_compact); |
| 1527 | 1538 |
| 1528 // Updates the allocation pointer to the relocation top after a mark-compact | 1539 // Updates the allocation pointer to the relocation top after a mark-compact |
| 1529 // collection. | 1540 // collection. |
| 1530 virtual void MCCommitRelocationInfo(); | 1541 virtual void MCCommitRelocationInfo(); |
| 1531 | 1542 |
| 1532 #ifdef DEBUG | 1543 #ifdef DEBUG |
| 1533 // Verify integrity of this space. | |
| 1534 virtual void Verify(); | |
| 1535 | |
| 1536 // Implement by subclasses to verify an actual object in the space. | |
| 1537 virtual void VerifyObject(HeapObject* obj) = 0; | |
| 1538 | |
| 1539 // Reports statistic info of the space | 1544 // Reports statistic info of the space |
| 1540 void ReportStatistics(); | 1545 void ReportStatistics(); |
| 1541 | 1546 |
| 1542 // Dump the remembered sets in the space to stdout. | 1547 // Dump the remembered sets in the space to stdout. |
| 1543 void PrintRSet(); | 1548 void PrintRSet(); |
| 1544 #endif | 1549 #endif |
| 1545 | 1550 |
| 1546 protected: | 1551 protected: |
| 1547 // Virtual function in the superclass. Slow path of AllocateRaw. | 1552 // Virtual function in the superclass. Slow path of AllocateRaw. |
| 1548 HeapObject* SlowAllocateRaw(int size_in_bytes); | 1553 HeapObject* SlowAllocateRaw(int size_in_bytes); |
| 1549 | 1554 |
| 1550 // Virtual function in the superclass. Allocate linearly at the start of | 1555 // Virtual function in the superclass. Allocate linearly at the start of |
| 1551 // the page after current_page (there is assumed to be one). | 1556 // the page after current_page (there is assumed to be one). |
| 1552 HeapObject* AllocateInNextPage(Page* current_page, int size_in_bytes); | 1557 HeapObject* AllocateInNextPage(Page* current_page, int size_in_bytes); |
| 1553 | 1558 |
| 1554 private: | 1559 private: |
| 1555 // The size of objects in this space. | 1560 // The size of objects in this space. |
| 1556 int object_size_in_bytes_; | 1561 int object_size_in_bytes_; |
| 1557 | 1562 |
| 1558 // The name of this space. | 1563 // The name of this space. |
| 1559 const char* name_; | 1564 const char* name_; |
| 1560 | 1565 |
| 1561 // The space's free list. | 1566 // The space's free list. |
| 1562 FixedSizeFreeList free_list_; | 1567 FixedSizeFreeList free_list_; |
| 1563 | |
| 1564 // Bytes of each page that cannot be allocated. | |
| 1565 int page_extra_; | |
| 1566 }; | 1568 }; |
| 1567 | 1569 |
| 1568 | 1570 |
| 1569 // ----------------------------------------------------------------------------- | 1571 // ----------------------------------------------------------------------------- |
| 1570 // Old space for all map objects | 1572 // Old space for all map objects |
| 1571 | 1573 |
| 1572 class MapSpace : public FixedSpace { | 1574 class MapSpace : public FixedSpace { |
| 1573 public: | 1575 public: |
| 1574 // Creates a map space object with a maximum capacity. | 1576 // Creates a map space object with a maximum capacity. |
| 1575 MapSpace(int max_capacity, AllocationSpace id) | 1577 MapSpace(int max_capacity, AllocationSpace id) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 | 1792 |
| 1791 private: | 1793 private: |
| 1792 LargeObjectChunk* current_; | 1794 LargeObjectChunk* current_; |
| 1793 HeapObjectCallback size_func_; | 1795 HeapObjectCallback size_func_; |
| 1794 }; | 1796 }; |
| 1795 | 1797 |
| 1796 | 1798 |
| 1797 } } // namespace v8::internal | 1799 } } // namespace v8::internal |
| 1798 | 1800 |
| 1799 #endif // V8_SPACES_H_ | 1801 #endif // V8_SPACES_H_ |
| OLD | NEW |