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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + | 540 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + |
541 kPointerSize + kPointerSize + | 541 kPointerSize + kPointerSize + |
542 kPointerSize + kPointerSize + kPointerSize + kIntSize; | 542 kPointerSize + kPointerSize + kPointerSize + kIntSize; |
543 | 543 |
544 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; | 544 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; |
545 | 545 |
546 static const size_t kWriteBarrierCounterOffset = | 546 static const size_t kWriteBarrierCounterOffset = |
547 kSlotsBufferOffset + kPointerSize + kPointerSize; | 547 kSlotsBufferOffset + kPointerSize + kPointerSize; |
548 | 548 |
549 static const size_t kHeaderSize = kWriteBarrierCounterOffset + kPointerSize + | 549 static const size_t kHeaderSize = kWriteBarrierCounterOffset + kPointerSize + |
550 kIntSize + kIntSize + kPointerSize; | 550 kIntSize + kIntSize + kPointerSize + |
551 5 * kPointerSize; | |
551 | 552 |
552 static const int kBodyOffset = | 553 static const int kBodyOffset = |
553 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); | 554 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); |
554 | 555 |
555 // The start offset of the object area in a page. Aligned to both maps and | 556 // The start offset of the object area in a page. Aligned to both maps and |
556 // code alignment to be suitable for both. Also aligned to 32 words because | 557 // code alignment to be suitable for both. Also aligned to 32 words because |
557 // the marking bitmap is arranged in 32 bit chunks. | 558 // the marking bitmap is arranged in 32 bit chunks. |
558 static const int kObjectStartAlignment = 32 * kPointerSize; | 559 static const int kObjectStartAlignment = 32 * kPointerSize; |
559 static const int kObjectStartOffset = kBodyOffset - 1 + | 560 static const int kObjectStartOffset = kBodyOffset - 1 + |
560 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); | 561 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 bool WasSweptPrecisely() { return IsFlagSet(WAS_SWEPT_PRECISELY); } | 791 bool WasSweptPrecisely() { return IsFlagSet(WAS_SWEPT_PRECISELY); } |
791 bool WasSweptConservatively() { return IsFlagSet(WAS_SWEPT_CONSERVATIVELY); } | 792 bool WasSweptConservatively() { return IsFlagSet(WAS_SWEPT_CONSERVATIVELY); } |
792 bool WasSwept() { return WasSweptPrecisely() || WasSweptConservatively(); } | 793 bool WasSwept() { return WasSweptPrecisely() || WasSweptConservatively(); } |
793 | 794 |
794 void MarkSweptPrecisely() { SetFlag(WAS_SWEPT_PRECISELY); } | 795 void MarkSweptPrecisely() { SetFlag(WAS_SWEPT_PRECISELY); } |
795 void MarkSweptConservatively() { SetFlag(WAS_SWEPT_CONSERVATIVELY); } | 796 void MarkSweptConservatively() { SetFlag(WAS_SWEPT_CONSERVATIVELY); } |
796 | 797 |
797 void ClearSweptPrecisely() { ClearFlag(WAS_SWEPT_PRECISELY); } | 798 void ClearSweptPrecisely() { ClearFlag(WAS_SWEPT_PRECISELY); } |
798 void ClearSweptConservatively() { ClearFlag(WAS_SWEPT_CONSERVATIVELY); } | 799 void ClearSweptConservatively() { ClearFlag(WAS_SWEPT_CONSERVATIVELY); } |
799 | 800 |
801 void ResetFreeListStatistics(); | |
802 | |
803 #define FRAGMENTATION_STATS_ACCESSORS(type, name) \ | |
804 type name() { return name##_; } \ | |
805 void set_##name(type name) { name##_ = name; } \ | |
806 void add_##name(type name) { name##_ += name; } | |
807 | |
808 FRAGMENTATION_STATS_ACCESSORS(intptr_t, non_available_small_blocks) | |
809 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_small_free_list) | |
810 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_medium_free_list) | |
811 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_large_free_list) | |
812 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_huge_free_list) | |
813 | |
814 #undef FRAGMENTATION_STATS_ACCESSORS | |
815 | |
800 #ifdef DEBUG | 816 #ifdef DEBUG |
801 void Print(); | 817 void Print(); |
802 #endif // DEBUG | 818 #endif // DEBUG |
803 | 819 |
820 private: | |
821 intptr_t available_in_small_free_list_; | |
822 intptr_t available_in_medium_free_list_; | |
823 intptr_t available_in_large_free_list_; | |
824 intptr_t available_in_huge_free_list_; | |
825 intptr_t non_available_small_blocks_; | |
Michael Starzinger
2013/04/10 07:59:31
Let's move the fields to MemoryChunk, because that
Hannes Payer (out of office)
2013/04/10 08:05:57
Done.
| |
826 | |
804 friend class MemoryAllocator; | 827 friend class MemoryAllocator; |
805 }; | 828 }; |
806 | 829 |
807 | 830 |
808 STATIC_CHECK(sizeof(Page) <= MemoryChunk::kHeaderSize); | 831 STATIC_CHECK(sizeof(Page) <= MemoryChunk::kHeaderSize); |
809 | 832 |
810 | 833 |
811 class LargePage : public MemoryChunk { | 834 class LargePage : public MemoryChunk { |
812 public: | 835 public: |
813 HeapObject* GetObject() { | 836 HeapObject* GetObject() { |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1425 } | 1448 } |
1426 | 1449 |
1427 intptr_t Concatenate(FreeListCategory* category); | 1450 intptr_t Concatenate(FreeListCategory* category); |
1428 | 1451 |
1429 void Reset(); | 1452 void Reset(); |
1430 | 1453 |
1431 void Free(FreeListNode* node, int size_in_bytes); | 1454 void Free(FreeListNode* node, int size_in_bytes); |
1432 | 1455 |
1433 FreeListNode* PickNodeFromList(int *node_size); | 1456 FreeListNode* PickNodeFromList(int *node_size); |
1434 | 1457 |
1435 intptr_t CountFreeListItemsInList(Page* p); | |
1436 | |
1437 intptr_t EvictFreeListItemsInList(Page* p); | 1458 intptr_t EvictFreeListItemsInList(Page* p); |
1438 | 1459 |
1439 void RepairFreeList(Heap* heap); | 1460 void RepairFreeList(Heap* heap); |
1440 | 1461 |
1441 FreeListNode** GetTopAddress() { return &top_; } | 1462 FreeListNode** GetTopAddress() { return &top_; } |
1442 FreeListNode* top() const { return top_; } | 1463 FreeListNode* top() const { return top_; } |
1443 void set_top(FreeListNode* top) { top_ = top; } | 1464 void set_top(FreeListNode* top) { top_ = top; } |
1444 | 1465 |
1445 FreeListNode** GetEndAddress() { return &end_; } | 1466 FreeListNode** GetEndAddress() { return &end_; } |
1446 FreeListNode* end() const { return end_; } | 1467 FreeListNode* end() const { return end_; } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 | 1542 |
1522 #ifdef DEBUG | 1543 #ifdef DEBUG |
1523 void Zap(); | 1544 void Zap(); |
1524 intptr_t SumFreeLists(); | 1545 intptr_t SumFreeLists(); |
1525 bool IsVeryLong(); | 1546 bool IsVeryLong(); |
1526 #endif | 1547 #endif |
1527 | 1548 |
1528 // Used after booting the VM. | 1549 // Used after booting the VM. |
1529 void RepairLists(Heap* heap); | 1550 void RepairLists(Heap* heap); |
1530 | 1551 |
1531 struct SizeStats { | |
1532 intptr_t Total() { | |
1533 return small_size_ + medium_size_ + large_size_ + huge_size_; | |
1534 } | |
1535 | |
1536 intptr_t small_size_; | |
1537 intptr_t medium_size_; | |
1538 intptr_t large_size_; | |
1539 intptr_t huge_size_; | |
1540 }; | |
1541 | |
1542 void CountFreeListItems(Page* p, SizeStats* sizes); | |
1543 | |
1544 intptr_t EvictFreeListItems(Page* p); | 1552 intptr_t EvictFreeListItems(Page* p); |
1545 | 1553 |
1546 FreeListCategory* small_list() { return &small_list_; } | 1554 FreeListCategory* small_list() { return &small_list_; } |
1547 FreeListCategory* medium_list() { return &medium_list_; } | 1555 FreeListCategory* medium_list() { return &medium_list_; } |
1548 FreeListCategory* large_list() { return &large_list_; } | 1556 FreeListCategory* large_list() { return &large_list_; } |
1549 FreeListCategory* huge_list() { return &huge_list_; } | 1557 FreeListCategory* huge_list() { return &huge_list_; } |
1550 | 1558 |
1551 private: | 1559 private: |
1552 // The size range of blocks, in bytes. | 1560 // The size range of blocks, in bytes. |
1553 static const int kMinBlockSize = 3 * kPointerSize; | 1561 static const int kMinBlockSize = 3 * kPointerSize; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1618 // Current capacity without growing (Size() + Available()). | 1626 // Current capacity without growing (Size() + Available()). |
1619 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1627 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
1620 | 1628 |
1621 // Total amount of memory committed for this space. For paged | 1629 // Total amount of memory committed for this space. For paged |
1622 // spaces this equals the capacity. | 1630 // spaces this equals the capacity. |
1623 intptr_t CommittedMemory() { return Capacity(); } | 1631 intptr_t CommittedMemory() { return Capacity(); } |
1624 | 1632 |
1625 // Approximate amount of physical memory committed for this space. | 1633 // Approximate amount of physical memory committed for this space. |
1626 size_t CommittedPhysicalMemory(); | 1634 size_t CommittedPhysicalMemory(); |
1627 | 1635 |
1636 struct SizeStats { | |
1637 intptr_t Total() { | |
1638 return small_size_ + medium_size_ + large_size_ + huge_size_; | |
1639 } | |
1640 | |
1641 intptr_t small_size_; | |
1642 intptr_t medium_size_; | |
1643 intptr_t large_size_; | |
1644 intptr_t huge_size_; | |
1645 }; | |
1646 | |
1647 void ObtainFreeListStatistics(Page* p, SizeStats* sizes); | |
1648 void ResetFreeListStatistics(); | |
1649 | |
1628 // Sets the capacity, the available space and the wasted space to zero. | 1650 // Sets the capacity, the available space and the wasted space to zero. |
1629 // The stats are rebuilt during sweeping by adding each page to the | 1651 // The stats are rebuilt during sweeping by adding each page to the |
1630 // capacity and the size when it is encountered. As free spaces are | 1652 // capacity and the size when it is encountered. As free spaces are |
1631 // discovered during the sweeping they are subtracted from the size and added | 1653 // discovered during the sweeping they are subtracted from the size and added |
1632 // to the available and wasted totals. | 1654 // to the available and wasted totals. |
1633 void ClearStats() { | 1655 void ClearStats() { |
1634 accounting_stats_.ClearSizeWaste(); | 1656 accounting_stats_.ClearSizeWaste(); |
1657 ResetFreeListStatistics(); | |
1635 } | 1658 } |
1636 | 1659 |
1637 // Increases the number of available bytes of that space. | 1660 // Increases the number of available bytes of that space. |
1638 void AddToAccountingStats(intptr_t bytes) { | 1661 void AddToAccountingStats(intptr_t bytes) { |
1639 accounting_stats_.DeallocateBytes(bytes); | 1662 accounting_stats_.DeallocateBytes(bytes); |
1640 } | 1663 } |
1641 | 1664 |
1642 // Available bytes without growing. These are the bytes on the free list. | 1665 // Available bytes without growing. These are the bytes on the free list. |
1643 // The bytes in the linear allocation area are not included in this total | 1666 // The bytes in the linear allocation area are not included in this total |
1644 // because updating the stats would slow down allocation. New pages are | 1667 // because updating the stats would slow down allocation. New pages are |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1778 // AdvanceSweeper with size_in_bytes is called. | 1801 // AdvanceSweeper with size_in_bytes is called. |
1779 bool EnsureSweeperProgress(intptr_t size_in_bytes); | 1802 bool EnsureSweeperProgress(intptr_t size_in_bytes); |
1780 | 1803 |
1781 bool IsLazySweepingComplete() { | 1804 bool IsLazySweepingComplete() { |
1782 return !first_unswept_page_->is_valid(); | 1805 return !first_unswept_page_->is_valid(); |
1783 } | 1806 } |
1784 | 1807 |
1785 Page* FirstPage() { return anchor_.next_page(); } | 1808 Page* FirstPage() { return anchor_.next_page(); } |
1786 Page* LastPage() { return anchor_.prev_page(); } | 1809 Page* LastPage() { return anchor_.prev_page(); } |
1787 | 1810 |
1788 void CountFreeListItems(Page* p, FreeList::SizeStats* sizes) { | |
1789 free_list_.CountFreeListItems(p, sizes); | |
1790 } | |
1791 | |
1792 void EvictEvacuationCandidatesFromFreeLists(); | 1811 void EvictEvacuationCandidatesFromFreeLists(); |
1793 | 1812 |
1794 bool CanExpand(); | 1813 bool CanExpand(); |
1795 | 1814 |
1796 // Returns the number of total pages in this space. | 1815 // Returns the number of total pages in this space. |
1797 int CountTotalPages(); | 1816 int CountTotalPages(); |
1798 | 1817 |
1799 // Return size of allocatable area on a page in this space. | 1818 // Return size of allocatable area on a page in this space. |
1800 inline int AreaSize() { | 1819 inline int AreaSize() { |
1801 return area_size_; | 1820 return area_size_; |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2826 } | 2845 } |
2827 // Must be small, since an iteration is used for lookup. | 2846 // Must be small, since an iteration is used for lookup. |
2828 static const int kMaxComments = 64; | 2847 static const int kMaxComments = 64; |
2829 }; | 2848 }; |
2830 #endif | 2849 #endif |
2831 | 2850 |
2832 | 2851 |
2833 } } // namespace v8::internal | 2852 } } // namespace v8::internal |
2834 | 2853 |
2835 #endif // V8_SPACES_H_ | 2854 #endif // V8_SPACES_H_ |
OLD | NEW |