Changeset 77082 in webkit
- Timestamp:
- Jan 29, 2011 10:23:13 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r77081 r77082 1 2011-01-29 Geoffrey Garen <ggaren@apple.com> 2 3 Reviewed by Cameron Zwarich. 4 5 Simplified Heap iteration 6 https://bugs.webkit.org/show_bug.cgi?id=53393 7 8 * runtime/CollectorHeapIterator.h: 9 (JSC::CollectorHeapIterator::isValid): 10 (JSC::CollectorHeapIterator::isLive): 11 (JSC::CollectorHeapIterator::advance): Removed "max" argument to 12 advance because it's a constant. 13 (JSC::LiveObjectIterator::LiveObjectIterator): 14 (JSC::LiveObjectIterator::operator++): 15 (JSC::DeadObjectIterator::DeadObjectIterator): 16 (JSC::DeadObjectIterator::operator++): 17 (JSC::ObjectIterator::ObjectIterator): 18 (JSC::ObjectIterator::operator++): Factored out common checks into 19 two helper functions -- isValid() for "Am I past the end?" and isLive() 20 for "Is the cell I'm pointing to live?". 21 22 * runtime/MarkedSpace.cpp: 23 (JSC::MarkedSpace::freeBlock): 24 (JSC::MarkedSpace::sweep): Always sweep from the beginning of the heap 25 to the end, to avoid making sweep subtly reliant on internal Heap state. 26 (JSC::MarkedSpace::primaryHeapBegin): 27 (JSC::MarkedSpace::primaryHeapEnd): Always be explicit about where 28 iteration begins. 29 1 30 2011-01-29 Geoffrey Garen <ggaren@apple.com> 2 31 -
trunk/Source/JavaScriptCore/runtime/CollectorHeapIterator.h
r75443 r77082 39 39 protected: 40 40 CollectorHeapIterator(CollectorHeap&, size_t startBlock, size_t startCell); 41 void advance(size_t max); 41 void advance(); 42 bool isValid(); 43 bool isLive(); 42 44 43 45 CollectorHeap& m_heap; … … 76 78 } 77 79 80 inline bool CollectorHeapIterator::isValid() 81 { 82 return m_block < m_heap.usedBlocks; 83 } 84 85 inline bool CollectorHeapIterator::isLive() 86 { 87 return m_block < m_heap.nextBlock 88 || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell) 89 || (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell)); 90 } 91 78 92 inline JSCell* CollectorHeapIterator::operator*() const 79 93 { … … 83 97 // Iterators advance up to the next-to-last -- and not the last -- cell in a 84 98 // block, since the last cell is a dummy sentinel. 85 inline void CollectorHeapIterator::advance( size_t max)99 inline void CollectorHeapIterator::advance() 86 100 { 87 101 ++m_cell; 88 if (m_cell == max) {102 if (m_cell == HeapConstants::cellsPerBlock - 1) { 89 103 m_cell = 0; 90 104 ++m_block; … … 93 107 94 108 inline LiveObjectIterator::LiveObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell) 95 : CollectorHeapIterator(heap, startBlock, startCell - 1)109 : CollectorHeapIterator(heap, startBlock, startCell) 96 110 { 97 ++(*this); 111 if (isValid() && !isLive()) 112 ++(*this); 98 113 } 99 114 100 115 inline LiveObjectIterator& LiveObjectIterator::operator++() 101 116 { 102 advance(HeapConstants::cellsPerBlock - 1); 103 if (m_block < m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell)) 104 return *this; 105 106 while (m_block < m_heap.usedBlocks && !m_heap.collectorBlock(m_block)->marked.get(m_cell)) 107 advance(HeapConstants::cellsPerBlock - 1); 117 do { 118 advance(); 119 } while (isValid() && !isLive()); 108 120 return *this; 109 121 } 110 122 111 123 inline DeadObjectIterator::DeadObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell) 112 : CollectorHeapIterator(heap, startBlock, startCell - 1)124 : CollectorHeapIterator(heap, startBlock, startCell) 113 125 { 114 ++(*this); 126 if (isValid() && isLive()) 127 ++(*this); 115 128 } 116 129 … … 118 131 { 119 132 do { 120 advance(HeapConstants::cellsPerBlock - 1); 121 ASSERT(m_block > m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell >= m_heap.nextCell)); 122 } while (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell)); 133 advance(); 134 } while (isValid() && isLive()); 123 135 return *this; 124 136 } 125 137 126 138 inline ObjectIterator::ObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell) 127 : CollectorHeapIterator(heap, startBlock, startCell - 1)139 : CollectorHeapIterator(heap, startBlock, startCell) 128 140 { 129 ++(*this); 141 if (isValid()) 142 ++(*this); 130 143 } 131 144 132 145 inline ObjectIterator& ObjectIterator::operator++() 133 146 { 134 advance( HeapConstants::cellsPerBlock - 1);147 advance(); 135 148 return *this; 136 149 } -
trunk/Source/JavaScriptCore/runtime/MarkedSpace.cpp
r77081 r77082 92 92 NEVER_INLINE void MarkedSpace::freeBlock(size_t block) 93 93 { 94 ObjectIterator it(m_heap, block );95 ObjectIterator end(m_heap, block + 1 );94 ObjectIterator it(m_heap, block, 0); 95 ObjectIterator end(m_heap, block + 1, 0); 96 96 for ( ; it != end; ++it) 97 97 (*it)->~JSCell(); … … 252 252 #endif 253 253 254 DeadObjectIterator it(m_heap, m_heap.nextBlock, m_heap.nextCell);255 DeadObjectIterator end(m_heap, m_heap.usedBlocks );254 DeadObjectIterator it(m_heap, 0, 0); 255 DeadObjectIterator end(m_heap, m_heap.usedBlocks, 0); 256 256 for ( ; it != end; ++it) { 257 257 JSCell* cell = *it; … … 301 301 LiveObjectIterator MarkedSpace::primaryHeapBegin() 302 302 { 303 return LiveObjectIterator(m_heap, 0 );303 return LiveObjectIterator(m_heap, 0, 0); 304 304 } 305 305 306 306 LiveObjectIterator MarkedSpace::primaryHeapEnd() 307 307 { 308 return LiveObjectIterator(m_heap, m_heap.usedBlocks );308 return LiveObjectIterator(m_heap, m_heap.usedBlocks, 0); 309 309 } 310 310
Note: See TracChangeset
for help on using the changeset viewer.