OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 bool ContainsPageFreeListItems(Page* p); | 1687 bool ContainsPageFreeListItems(Page* p); |
1688 | 1688 |
1689 FreeListCategory* small_list() { return &small_list_; } | 1689 FreeListCategory* small_list() { return &small_list_; } |
1690 FreeListCategory* medium_list() { return &medium_list_; } | 1690 FreeListCategory* medium_list() { return &medium_list_; } |
1691 FreeListCategory* large_list() { return &large_list_; } | 1691 FreeListCategory* large_list() { return &large_list_; } |
1692 FreeListCategory* huge_list() { return &huge_list_; } | 1692 FreeListCategory* huge_list() { return &huge_list_; } |
1693 | 1693 |
1694 PagedSpace* owner() { return owner_; } | 1694 PagedSpace* owner() { return owner_; } |
1695 | 1695 |
1696 private: | 1696 private: |
1697 enum FreeListCategoryType { kSmall, kMedium, kLarge, kHuge }; | |
1698 | |
1699 // The size range of blocks, in bytes. | 1697 // The size range of blocks, in bytes. |
1700 static const int kMinBlockSize = 3 * kPointerSize; | 1698 static const int kMinBlockSize = 3 * kPointerSize; |
1701 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; | 1699 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; |
1702 | 1700 |
1703 static const int kSmallListMin = 0x1f * kPointerSize; | 1701 static const int kSmallListMin = 0x1f * kPointerSize; |
1704 static const int kSmallListMax = 0xff * kPointerSize; | 1702 static const int kSmallListMax = 0xff * kPointerSize; |
1705 static const int kMediumListMax = 0x7ff * kPointerSize; | 1703 static const int kMediumListMax = 0x7ff * kPointerSize; |
1706 static const int kLargeListMax = 0x3fff * kPointerSize; | 1704 static const int kLargeListMax = 0x3fff * kPointerSize; |
1707 static const int kSmallAllocationMax = kSmallListMin; | 1705 static const int kSmallAllocationMax = kSmallListMin; |
1708 static const int kMediumAllocationMax = kSmallListMax; | 1706 static const int kMediumAllocationMax = kSmallListMax; |
1709 static const int kLargeAllocationMax = kMediumListMax; | 1707 static const int kLargeAllocationMax = kMediumListMax; |
1710 | 1708 |
1711 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); | 1709 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); |
1712 FreeSpace* FindNodeIn(FreeListCategoryType category, int* node_size); | |
1713 | |
1714 FreeListCategory* GetFreeListCategory(FreeListCategoryType category) { | |
1715 switch (category) { | |
1716 case kSmall: | |
1717 return &small_list_; | |
1718 case kMedium: | |
1719 return &medium_list_; | |
1720 case kLarge: | |
1721 return &large_list_; | |
1722 case kHuge: | |
1723 return &huge_list_; | |
1724 default: | |
1725 UNREACHABLE(); | |
1726 } | |
1727 UNREACHABLE(); | |
1728 return nullptr; | |
1729 } | |
1730 | |
1731 void UpdateFragmentationStats(FreeListCategoryType category, Address address, | |
1732 int size); | |
1733 | 1710 |
1734 PagedSpace* owner_; | 1711 PagedSpace* owner_; |
1735 Heap* heap_; | 1712 Heap* heap_; |
1736 FreeListCategory small_list_; | 1713 FreeListCategory small_list_; |
1737 FreeListCategory medium_list_; | 1714 FreeListCategory medium_list_; |
1738 FreeListCategory large_list_; | 1715 FreeListCategory large_list_; |
1739 FreeListCategory huge_list_; | 1716 FreeListCategory huge_list_; |
1740 | 1717 |
1741 friend class PagedSpace; | |
1742 | |
1743 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1718 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
1744 }; | 1719 }; |
1745 | 1720 |
1746 | 1721 |
1747 class AllocationResult { | 1722 class AllocationResult { |
1748 public: | 1723 public: |
1749 // Implicit constructor from Object*. | 1724 // Implicit constructor from Object*. |
1750 AllocationResult(Object* object) // NOLINT | 1725 AllocationResult(Object* object) // NOLINT |
1751 : object_(object) { | 1726 : object_(object) { |
1752 // AllocationResults can't return Smis, which are used to represent | 1727 // AllocationResults can't return Smis, which are used to represent |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2015 inline int AreaSize() { return area_size_; } | 1990 inline int AreaSize() { return area_size_; } |
2016 | 1991 |
2017 // Merges {other} into the current space. Note that this modifies {other}, | 1992 // Merges {other} into the current space. Note that this modifies {other}, |
2018 // e.g., removes its bump pointer area and resets statistics. | 1993 // e.g., removes its bump pointer area and resets statistics. |
2019 void MergeCompactionSpace(CompactionSpace* other); | 1994 void MergeCompactionSpace(CompactionSpace* other); |
2020 | 1995 |
2021 void MoveOverFreeMemory(PagedSpace* other); | 1996 void MoveOverFreeMemory(PagedSpace* other); |
2022 | 1997 |
2023 virtual bool is_local() { return false; } | 1998 virtual bool is_local() { return false; } |
2024 | 1999 |
2025 // Divide {this} free lists up among {other_free_lists} up to some certain | |
2026 // {limit} of bytes. Note that this operation eventually needs to iterate | |
2027 // over nodes one-by-one, making it a potentially slow operation. | |
2028 void DivideFreeLists(FreeList** other_free_lists, int num, intptr_t limit); | |
2029 | |
2030 // Adds memory starting at {start} of {size_in_bytes} to the space. | |
2031 void AddMemory(Address start, int size_in_bytes) { | |
2032 IncreaseCapacity(size_in_bytes); | |
2033 Free(start, size_in_bytes); | |
2034 } | |
2035 | |
2036 // Tries to remove some memory from {this} free lists. We try to remove | |
2037 // as much memory as possible, i.e., we check the free lists from huge | |
2038 // to small. | |
2039 FreeSpace* TryRemoveMemory(); | |
2040 | |
2041 protected: | 2000 protected: |
2042 // PagedSpaces that should be included in snapshots have different, i.e., | 2001 // PagedSpaces that should be included in snapshots have different, i.e., |
2043 // smaller, initial pages. | 2002 // smaller, initial pages. |
2044 virtual bool snapshotable() { return true; } | 2003 virtual bool snapshotable() { return true; } |
2045 | 2004 |
2046 FreeList* free_list() { return &free_list_; } | 2005 FreeList* free_list() { return &free_list_; } |
2047 | 2006 |
2048 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2007 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2049 | 2008 |
2050 // Cleans up the space, frees all pages in this space except those belonging | 2009 // Cleans up the space, frees all pages in this space except those belonging |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 }; | 2737 }; |
2779 | 2738 |
2780 // ----------------------------------------------------------------------------- | 2739 // ----------------------------------------------------------------------------- |
2781 // Compaction space that is used temporarily during compaction. | 2740 // Compaction space that is used temporarily during compaction. |
2782 | 2741 |
2783 class CompactionSpace : public PagedSpace { | 2742 class CompactionSpace : public PagedSpace { |
2784 public: | 2743 public: |
2785 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2744 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
2786 : PagedSpace(heap, id, executable) {} | 2745 : PagedSpace(heap, id, executable) {} |
2787 | 2746 |
| 2747 // Adds external memory starting at {start} of {size_in_bytes} to the space. |
| 2748 void AddExternalMemory(Address start, int size_in_bytes) { |
| 2749 IncreaseCapacity(size_in_bytes); |
| 2750 Free(start, size_in_bytes); |
| 2751 } |
| 2752 |
2788 virtual bool is_local() { return true; } | 2753 virtual bool is_local() { return true; } |
2789 | 2754 |
2790 protected: | 2755 protected: |
2791 // The space is temporary and not included in any snapshots. | 2756 // The space is temporary and not included in any snapshots. |
2792 virtual bool snapshotable() { return false; } | 2757 virtual bool snapshotable() { return false; } |
2793 }; | 2758 }; |
2794 | 2759 |
2795 | 2760 |
2796 // A collection of |CompactionSpace|s used by a single compaction task. | 2761 // A collection of |CompactionSpace|s used by a single compaction task. |
2797 class CompactionSpaceCollection : public Malloced { | 2762 class CompactionSpaceCollection : public Malloced { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3012 count = 0; | 2977 count = 0; |
3013 } | 2978 } |
3014 // Must be small, since an iteration is used for lookup. | 2979 // Must be small, since an iteration is used for lookup. |
3015 static const int kMaxComments = 64; | 2980 static const int kMaxComments = 64; |
3016 }; | 2981 }; |
3017 #endif | 2982 #endif |
3018 } | 2983 } |
3019 } // namespace v8::internal | 2984 } // namespace v8::internal |
3020 | 2985 |
3021 #endif // V8_HEAP_SPACES_H_ | 2986 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |