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 FreeListCat { kSmall, kMedium, kLarge, kHuge }; | |
Hannes Payer (out of office)
2015/09/23 12:00:43
FreeListCategoryType?
Michael Lippautz
2015/09/23 12:03:58
Done.
| |
1698 | |
1697 // The size range of blocks, in bytes. | 1699 // The size range of blocks, in bytes. |
1698 static const int kMinBlockSize = 3 * kPointerSize; | 1700 static const int kMinBlockSize = 3 * kPointerSize; |
1699 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; | 1701 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; |
1700 | 1702 |
1701 static const int kSmallListMin = 0x1f * kPointerSize; | 1703 static const int kSmallListMin = 0x1f * kPointerSize; |
1702 static const int kSmallListMax = 0xff * kPointerSize; | 1704 static const int kSmallListMax = 0xff * kPointerSize; |
1703 static const int kMediumListMax = 0x7ff * kPointerSize; | 1705 static const int kMediumListMax = 0x7ff * kPointerSize; |
1704 static const int kLargeListMax = 0x3fff * kPointerSize; | 1706 static const int kLargeListMax = 0x3fff * kPointerSize; |
1705 static const int kSmallAllocationMax = kSmallListMin; | 1707 static const int kSmallAllocationMax = kSmallListMin; |
1706 static const int kMediumAllocationMax = kSmallListMax; | 1708 static const int kMediumAllocationMax = kSmallListMax; |
1707 static const int kLargeAllocationMax = kMediumListMax; | 1709 static const int kLargeAllocationMax = kMediumListMax; |
1708 | 1710 |
1709 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); | 1711 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); |
1712 FreeSpace* FindNodeIn(FreeListCat category, int* node_size); | |
1713 | |
1714 FreeListCategory* GetFreeListCategory(FreeListCat 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(FreeListCat category, Address address, | |
1732 int size); | |
1710 | 1733 |
1711 PagedSpace* owner_; | 1734 PagedSpace* owner_; |
1712 Heap* heap_; | 1735 Heap* heap_; |
1713 FreeListCategory small_list_; | 1736 FreeListCategory small_list_; |
1714 FreeListCategory medium_list_; | 1737 FreeListCategory medium_list_; |
1715 FreeListCategory large_list_; | 1738 FreeListCategory large_list_; |
1716 FreeListCategory huge_list_; | 1739 FreeListCategory huge_list_; |
1717 | 1740 |
1741 friend class PagedSpace; | |
1742 | |
1718 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1743 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
1719 }; | 1744 }; |
1720 | 1745 |
1721 | 1746 |
1722 class AllocationResult { | 1747 class AllocationResult { |
1723 public: | 1748 public: |
1724 // Implicit constructor from Object*. | 1749 // Implicit constructor from Object*. |
1725 AllocationResult(Object* object) // NOLINT | 1750 AllocationResult(Object* object) // NOLINT |
1726 : object_(object) { | 1751 : object_(object) { |
1727 // AllocationResults can't return Smis, which are used to represent | 1752 // AllocationResults can't return Smis, which are used to represent |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1990 inline int AreaSize() { return area_size_; } | 2015 inline int AreaSize() { return area_size_; } |
1991 | 2016 |
1992 // Merges {other} into the current space. Note that this modifies {other}, | 2017 // Merges {other} into the current space. Note that this modifies {other}, |
1993 // e.g., removes its bump pointer area and resets statistics. | 2018 // e.g., removes its bump pointer area and resets statistics. |
1994 void MergeCompactionSpace(CompactionSpace* other); | 2019 void MergeCompactionSpace(CompactionSpace* other); |
1995 | 2020 |
1996 void MoveOverFreeMemory(PagedSpace* other); | 2021 void MoveOverFreeMemory(PagedSpace* other); |
1997 | 2022 |
1998 virtual bool is_local() { return false; } | 2023 virtual bool is_local() { return false; } |
1999 | 2024 |
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 | |
2000 protected: | 2041 protected: |
2001 // PagedSpaces that should be included in snapshots have different, i.e., | 2042 // PagedSpaces that should be included in snapshots have different, i.e., |
2002 // smaller, initial pages. | 2043 // smaller, initial pages. |
2003 virtual bool snapshotable() { return true; } | 2044 virtual bool snapshotable() { return true; } |
2004 | 2045 |
2005 FreeList* free_list() { return &free_list_; } | 2046 FreeList* free_list() { return &free_list_; } |
2006 | 2047 |
2007 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2048 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2008 | 2049 |
2009 // Cleans up the space, frees all pages in this space except those belonging | 2050 // 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... | |
2737 }; | 2778 }; |
2738 | 2779 |
2739 // ----------------------------------------------------------------------------- | 2780 // ----------------------------------------------------------------------------- |
2740 // Compaction space that is used temporarily during compaction. | 2781 // Compaction space that is used temporarily during compaction. |
2741 | 2782 |
2742 class CompactionSpace : public PagedSpace { | 2783 class CompactionSpace : public PagedSpace { |
2743 public: | 2784 public: |
2744 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2785 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
2745 : PagedSpace(heap, id, executable) {} | 2786 : PagedSpace(heap, id, executable) {} |
2746 | 2787 |
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 | |
2753 virtual bool is_local() { return true; } | 2788 virtual bool is_local() { return true; } |
2754 | 2789 |
2755 protected: | 2790 protected: |
2756 // The space is temporary and not included in any snapshots. | 2791 // The space is temporary and not included in any snapshots. |
2757 virtual bool snapshotable() { return false; } | 2792 virtual bool snapshotable() { return false; } |
2758 }; | 2793 }; |
2759 | 2794 |
2760 | 2795 |
2761 // A collection of |CompactionSpace|s used by a single compaction task. | 2796 // A collection of |CompactionSpace|s used by a single compaction task. |
2762 class CompactionSpaceCollection : public Malloced { | 2797 class CompactionSpaceCollection : public Malloced { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2977 count = 0; | 3012 count = 0; |
2978 } | 3013 } |
2979 // Must be small, since an iteration is used for lookup. | 3014 // Must be small, since an iteration is used for lookup. |
2980 static const int kMaxComments = 64; | 3015 static const int kMaxComments = 64; |
2981 }; | 3016 }; |
2982 #endif | 3017 #endif |
2983 } | 3018 } |
2984 } // namespace v8::internal | 3019 } // namespace v8::internal |
2985 | 3020 |
2986 #endif // V8_HEAP_SPACES_H_ | 3021 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |