Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: src/heap/spaces.h

Issue 1696413002: [heap] Refactor free list counters in Page. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/heap/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 + kPointerSize // SlotSet* old_to_old_slots_; 401 + kPointerSize // SlotSet* old_to_old_slots_;
402 + kPointerSize; // SkipList* skip_list_; 402 + kPointerSize; // SkipList* skip_list_;
403 403
404 static const size_t kMinHeaderSize = 404 static const size_t kMinHeaderSize =
405 kWriteBarrierCounterOffset + 405 kWriteBarrierCounterOffset +
406 kIntptrSize // intptr_t write_barrier_counter_ 406 kIntptrSize // intptr_t write_barrier_counter_
407 + kPointerSize // AtomicValue high_water_mark_ 407 + kPointerSize // AtomicValue high_water_mark_
408 + kPointerSize // base::Mutex* mutex_ 408 + kPointerSize // base::Mutex* mutex_
409 + kPointerSize // base::AtomicWord parallel_sweeping_ 409 + kPointerSize // base::AtomicWord parallel_sweeping_
410 + kPointerSize // AtomicValue parallel_compaction_ 410 + kPointerSize // AtomicValue parallel_compaction_
411 + 5 * kPointerSize // AtomicNumber free-list statistics 411 + 2 * kPointerSize // AtomicNumber free-list statistics
412 + kPointerSize // AtomicValue next_chunk_ 412 + kPointerSize // AtomicValue next_chunk_
413 + kPointerSize; // AtomicValue prev_chunk_ 413 + kPointerSize; // AtomicValue prev_chunk_
414 414
415 // We add some more space to the computed header size to amount for missing 415 // We add some more space to the computed header size to amount for missing
416 // alignment requirements in our computation. 416 // alignment requirements in our computation.
417 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines. 417 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines.
418 static const size_t kHeaderSize = kMinHeaderSize; 418 static const size_t kHeaderSize = kMinHeaderSize;
419 419
420 static const int kBodyOffset = 420 static const int kBodyOffset =
421 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); 421 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // Assuming the initial allocation on a page is sequential, 698 // Assuming the initial allocation on a page is sequential,
699 // count highest number of bytes ever allocated on the page. 699 // count highest number of bytes ever allocated on the page.
700 AtomicValue<intptr_t> high_water_mark_; 700 AtomicValue<intptr_t> high_water_mark_;
701 701
702 base::Mutex* mutex_; 702 base::Mutex* mutex_;
703 703
704 AtomicValue<ConcurrentSweepingState> concurrent_sweeping_; 704 AtomicValue<ConcurrentSweepingState> concurrent_sweeping_;
705 AtomicValue<ParallelCompactingState> parallel_compaction_; 705 AtomicValue<ParallelCompactingState> parallel_compaction_;
706 706
707 // PagedSpace free-list statistics. 707 // PagedSpace free-list statistics.
708 AtomicNumber<intptr_t> available_in_small_free_list_; 708 AtomicNumber<intptr_t> available_in_free_list_;
709 AtomicNumber<intptr_t> available_in_medium_free_list_; 709 AtomicNumber<intptr_t> wasted_memory_;
710 AtomicNumber<intptr_t> available_in_large_free_list_;
711 AtomicNumber<intptr_t> available_in_huge_free_list_;
712 AtomicNumber<intptr_t> non_available_small_blocks_;
713 710
714 // next_chunk_ holds a pointer of type MemoryChunk 711 // next_chunk_ holds a pointer of type MemoryChunk
715 AtomicValue<MemoryChunk*> next_chunk_; 712 AtomicValue<MemoryChunk*> next_chunk_;
716 // prev_chunk_ holds a pointer of type MemoryChunk 713 // prev_chunk_ holds a pointer of type MemoryChunk
717 AtomicValue<MemoryChunk*> prev_chunk_; 714 AtomicValue<MemoryChunk*> prev_chunk_;
718 715
719 private: 716 private:
720 void InitializeReservedMemory() { reservation_.Reset(); } 717 void InitializeReservedMemory() { reservation_.Reset(); }
721 718
722 friend class MemoryAllocator; 719 friend class MemoryAllocator;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 DCHECK(SweepingDone()); 823 DCHECK(SweepingDone());
827 } 824 }
828 825
829 bool SweepingDone() { 826 bool SweepingDone() {
830 return concurrent_sweeping_state().Value() == kSweepingDone; 827 return concurrent_sweeping_state().Value() == kSweepingDone;
831 } 828 }
832 829
833 void ResetFreeListStatistics(); 830 void ResetFreeListStatistics();
834 831
835 int LiveBytesFromFreeList() { 832 int LiveBytesFromFreeList() {
836 return static_cast<int>( 833 return static_cast<int>(area_size() - wasted_memory() -
837 area_size() - non_available_small_blocks() - 834 available_in_free_list());
838 available_in_small_free_list() - available_in_medium_free_list() -
839 available_in_large_free_list() - available_in_huge_free_list());
840 } 835 }
841 836
842 #define FRAGMENTATION_STATS_ACCESSORS(type, name) \ 837 #define FRAGMENTATION_STATS_ACCESSORS(type, name) \
843 type name() { return name##_.Value(); } \ 838 type name() { return name##_.Value(); } \
844 void set_##name(type name) { name##_.SetValue(name); } \ 839 void set_##name(type name) { name##_.SetValue(name); } \
845 void add_##name(type name) { name##_.Increment(name); } 840 void add_##name(type name) { name##_.Increment(name); }
846 841
847 FRAGMENTATION_STATS_ACCESSORS(intptr_t, non_available_small_blocks) 842 FRAGMENTATION_STATS_ACCESSORS(intptr_t, wasted_memory)
848 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_small_free_list) 843 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_free_list)
849 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_medium_free_list)
850 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_large_free_list)
851 FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_huge_free_list)
852 844
853 #undef FRAGMENTATION_STATS_ACCESSORS 845 #undef FRAGMENTATION_STATS_ACCESSORS
854 846
855 void add_available_in_free_list(FreeListCategoryType type, intptr_t bytes) {
856 switch (type) {
857 case kSmall:
858 add_available_in_small_free_list(bytes);
859 break;
860 case kMedium:
861 add_available_in_medium_free_list(bytes);
862 break;
863 case kLarge:
864 add_available_in_large_free_list(bytes);
865 break;
866 case kHuge:
867 add_available_in_huge_free_list(bytes);
868 break;
869 default:
870 UNREACHABLE();
871 }
872 }
873
874 intptr_t available_in_free_list(FreeListCategoryType type) {
875 switch (type) {
876 case kSmall:
877 return available_in_small_free_list();
878 case kMedium:
879 return available_in_medium_free_list();
880 case kLarge:
881 return available_in_large_free_list();
882 case kHuge:
883 return available_in_huge_free_list();
884 default:
885 UNREACHABLE();
886 }
887 UNREACHABLE();
888 return 0;
889 }
890
891 #ifdef DEBUG 847 #ifdef DEBUG
892 void Print(); 848 void Print();
893 #endif // DEBUG 849 #endif // DEBUG
894 850
895 friend class MemoryAllocator; 851 friend class MemoryAllocator;
896 }; 852 };
897 853
898 854
899 class LargePage : public MemoryChunk { 855 class LargePage : public MemoryChunk {
900 public: 856 public:
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 static const int kMediumAllocationMax = kSmallListMax; 1748 static const int kMediumAllocationMax = kSmallListMax;
1793 static const int kLargeAllocationMax = kMediumListMax; 1749 static const int kLargeAllocationMax = kMediumListMax;
1794 1750
1795 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); 1751 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size);
1796 FreeSpace* FindNodeIn(FreeListCategoryType category, int* node_size); 1752 FreeSpace* FindNodeIn(FreeListCategoryType category, int* node_size);
1797 1753
1798 FreeListCategory* GetFreeListCategory(FreeListCategoryType category) { 1754 FreeListCategory* GetFreeListCategory(FreeListCategoryType category) {
1799 return &category_[category]; 1755 return &category_[category];
1800 } 1756 }
1801 1757
1758 FreeListCategoryType SelectFreeListCategoryType(size_t size_in_bytes) {
1759 if (size_in_bytes <= kSmallListMax) {
1760 return kSmall;
1761 } else if (size_in_bytes <= kMediumListMax) {
1762 return kMedium;
1763 } else if (size_in_bytes <= kLargeListMax) {
1764 return kLarge;
1765 }
1766 return kHuge;
1767 }
1768
1769 FreeListCategoryType SelectFastAllocationFreeListCategoryType(
1770 size_t size_in_bytes) {
1771 if (size_in_bytes <= kSmallAllocationMax) {
1772 return kSmall;
1773 } else if (size_in_bytes <= kMediumAllocationMax) {
1774 return kMedium;
1775 } else if (size_in_bytes <= kLargeAllocationMax) {
1776 return kLarge;
1777 }
1778 return kHuge;
1779 }
1780
1802 PagedSpace* owner_; 1781 PagedSpace* owner_;
1803 base::Mutex mutex_; 1782 base::Mutex mutex_;
1804 intptr_t wasted_bytes_; 1783 intptr_t wasted_bytes_;
1805 FreeListCategory category_[kNumberOfCategories]; 1784 FreeListCategory category_[kNumberOfCategories];
1806 1785
1807 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); 1786 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
1808 }; 1787 };
1809 1788
1810 1789
1811 class AllocationResult { 1790 class AllocationResult {
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
3039 count = 0; 3018 count = 0;
3040 } 3019 }
3041 // Must be small, since an iteration is used for lookup. 3020 // Must be small, since an iteration is used for lookup.
3042 static const int kMaxComments = 64; 3021 static const int kMaxComments = 64;
3043 }; 3022 };
3044 #endif 3023 #endif
3045 } // namespace internal 3024 } // namespace internal
3046 } // namespace v8 3025 } // namespace v8
3047 3026
3048 #endif // V8_HEAP_SPACES_H_ 3027 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698