Changeset 118019 in webkit for trunk/Source/JavaScriptCore/heap/Heap.cpp
- Timestamp:
- May 22, 2012, 12:17:57 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/heap/Heap.cpp
r117729 r118019 36 36 #include "WeakSetInlines.h" 37 37 #include <algorithm> 38 #include <wtf/RAMSize.h> 38 39 #include <wtf/CurrentTime.h> 39 40 40 41 41 using namespace std; … … 46 46 namespace { 47 47 48 #if CPU(X86) || CPU(X86_64) 49 static const size_t largeHeapSize = 16 * 1024 * 1024; 50 #elif PLATFORM(IOS) 51 static const size_t largeHeapSize = 8 * 1024 * 1024; 52 #else 53 static const size_t largeHeapSize = 512 * 1024; 54 #endif 55 static const size_t smallHeapSize = 512 * 1024; 48 static const size_t largeHeapSize = 32 * MB; // About 1.5X the average webpage. 49 static const size_t smallHeapSize = 1 * MB; // Matches the FastMalloc per-thread cache. 56 50 57 51 #if ENABLE(GC_LOGGING) … … 149 143 #endif 150 144 151 static size_t heapSizeForHint(HeapSize heapSize) 152 { 153 if (heapSize == LargeHeap) 154 return largeHeapSize; 155 ASSERT(heapSize == SmallHeap); 145 static inline size_t minHeapSize(HeapType heapType, size_t ramSize) 146 { 147 if (heapType == LargeHeap) 148 return min(largeHeapSize, ramSize / 4); 156 149 return smallHeapSize; 150 } 151 152 static inline size_t proportionalHeapSize(size_t heapSize, size_t ramSize) 153 { 154 // Try to stay under 1/2 RAM size to leave room for the DOM, rendering, networking, etc. 155 if (heapSize < ramSize / 4) 156 return 2 * heapSize; 157 if (heapSize < ramSize / 2) 158 return 1.5 * heapSize; 159 return 1.25 * heapSize; 157 160 } 158 161 … … 231 234 } // anonymous namespace 232 235 233 Heap::Heap(JSGlobalData* globalData, HeapSize heapSize) 234 : m_heapSize(heapSize) 235 , m_minBytesPerCycle(heapSizeForHint(heapSize)) 236 Heap::Heap(JSGlobalData* globalData, HeapType heapType) 237 : m_heapType(heapType) 238 , m_ramSize(ramSize()) 239 , m_minBytesPerCycle(minHeapSize(m_heapType, m_ramSize)) 236 240 , m_sizeAfterLastCollect(0) 237 241 , m_bytesAllocatedLimit(m_minBytesPerCycle) … … 723 727 } 724 728 725 // To avoid pathological GC churn in large heaps, we set the new allocation 726 // limit to be the current size of the heap. This heuristic 727 // is a bit arbitrary. Using the current size of the heap after this 728 // collection gives us a 2X multiplier, which is a 1:1 (heap size : 729 // new bytes allocated) proportion, and seems to work well in benchmarks. 730 size_t newSize = size(); 729 size_t currentHeapSize = size(); 731 730 if (fullGC) { 732 m_sizeAfterLastCollect = newSize; 733 m_bytesAllocatedLimit = max(newSize, m_minBytesPerCycle); 731 m_sizeAfterLastCollect = currentHeapSize; 732 733 // To avoid pathological GC churn in very small and very large heaps, we set 734 // the new allocation limit based on the current size of the heap, with a 735 // fixed minimum. 736 size_t maxHeapSize = max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize)); 737 m_bytesAllocatedLimit = maxHeapSize - currentHeapSize; 734 738 } 735 739 m_bytesAllocated = 0;
Note:
See TracChangeset
for help on using the changeset viewer.