Changeset 76425 in webkit
- Timestamp:
- Jan 21, 2011 8:27:18 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r76409 r76425 1 2011-01-21 Geoffrey Garen <ggaren@apple.com> 2 3 Reviewed by Maciej Stachowiak. 4 5 Cleaned up some conservative marking code. 6 https://bugs.webkit.org/show_bug.cgi?id=52946 7 8 SunSpider reports no change. 9 10 * interpreter/RegisterFile.h: No need for a special marking function, 11 since we already expose a start() and end(). 12 13 * runtime/Heap.cpp: 14 (JSC::Heap::registerFile): 15 (JSC::Heap::markRoots): 16 * runtime/Heap.h: 17 (JSC::Heap::contains): Migrated markConservatively() to the machine stack 18 marker class. Now, Heap just provides a contains() function, which the 19 machine stack marker uses for checking whether a pointer points into the heap. 20 21 * runtime/MachineStackMarker.cpp: 22 (JSC::MachineStackMarker::markCurrentThreadConservativelyInternal): 23 (JSC::MachineStackMarker::markOtherThreadConservatively): 24 (JSC::isPointerAligned): 25 (JSC::MachineStackMarker::markConservatively): 26 * runtime/MachineStackMarker.h: Move the conservative marking code here. 27 28 * runtime/MarkStack.h: 29 (JSC::ConservativeSet::add): 30 (JSC::ConservativeSet::mark): Changed to using a vector instead of hash 31 set. Vector seems to be a bit faster, and it generates smaller code. 32 33 * runtime/MarkedSpace.cpp: 34 (JSC::MarkedSpace::containsSlowCase): 35 * runtime/MarkedSpace.h: 36 (JSC::MarkedSpace::isCellAligned): 37 (JSC::MarkedSpace::isPossibleCell): 38 (JSC::MarkedSpace::contains): Kept the code for determining whether a 39 pointer pointed into marked space, and moved the code for marking 40 a set of conservative pointers into the machine stack marker. 41 42 * wtf/HashSet.h: 43 (WTF::::add): Added two missing inlines that I noticed while testing 44 vector vs hash set. 45 1 46 2011-01-21 Mark Rowe <mrowe@apple.com> 2 47 -
trunk/Source/JavaScriptCore/interpreter/RegisterFile.h
r76331 r76425 133 133 Register* lastGlobal() const { return m_start - m_numGlobals; } 134 134 135 void markCallFrames(ConservativeSet& conservativeSet, Heap* heap) { heap->markConservatively(conservativeSet, m_start, m_end); }136 137 135 static size_t committedByteCount(); 138 136 static void initializeThreading(); -
trunk/Source/JavaScriptCore/runtime/Heap.cpp
r76399 r76425 148 148 } 149 149 150 void Heap::markConservatively(ConservativeSet& conservativeSet, void* start, void* end)151 {152 m_markedSpace.markConservatively(conservativeSet, start, end);153 }154 155 150 void Heap::updateWeakGCHandles() 156 151 { … … 238 233 } 239 234 } 240 235 236 inline RegisterFile& Heap::registerFile() 237 { 238 return m_globalData->interpreter->registerFile(); 239 } 240 241 241 void Heap::markRoots() 242 242 { … … 259 259 ConservativeSet conservativeSet; 260 260 m_machineStackMarker.markMachineStackConservatively(conservativeSet); 261 m_ globalData->interpreter->registerFile().markCallFrames(conservativeSet, this);261 m_machineStackMarker.markConservatively(conservativeSet, registerFile().start(), registerFile().end()); 262 262 263 263 // Reset mark bits. -
trunk/Source/JavaScriptCore/runtime/Heap.h
r76399 r76425 32 32 namespace JSC { 33 33 34 class JSValue;35 class UString;36 34 class GCActivityCallback; 37 35 class JSCell; 38 36 class JSGlobalData; 39 37 class JSValue; 38 class JSValue; 40 39 class LiveObjectIterator; 40 class MarkStack; 41 41 class MarkedArgumentBuffer; 42 class MarkStack; 42 class RegisterFile; 43 class UString; 43 44 class WeakGCHandlePool; 44 45 … … 86 87 static bool checkMarkCell(const JSCell*); 87 88 static void markCell(JSCell*); 89 90 bool contains(void*); 88 91 89 92 WeakGCHandle* addWeakGCHandle(JSCell*); 90 91 void markConservatively(ConservativeSet&, void* start, void* end);92 93 93 94 void pushTempSortVector(WTF::Vector<ValueStringPair>*); … … 118 119 void updateWeakGCHandles(); 119 120 WeakGCHandlePool* weakGCHandlePool(size_t index); 121 122 RegisterFile& registerFile(); 120 123 121 124 MarkedSpace m_markedSpace; … … 153 156 } 154 157 158 inline bool Heap::contains(void* p) 159 { 160 return m_markedSpace.contains(p); 161 } 162 155 163 inline void Heap::reportExtraMemoryCost(size_t cost) 156 164 { -
trunk/Source/JavaScriptCore/runtime/MachineStackMarker.cpp
r76331 r76425 197 197 void NEVER_INLINE MachineStackMarker::markCurrentThreadConservativelyInternal(ConservativeSet& conservativeSet) 198 198 { 199 m _heap->markConservatively(conservativeSet, m_heap->globalData()->stack().current(), m_heap->globalData()->stack().origin());199 markConservatively(conservativeSet, m_heap->globalData()->stack().current(), m_heap->globalData()->stack().origin()); 200 200 } 201 201 … … 359 359 360 360 // mark the thread's registers 361 m _heap->markConservatively(conservativeSet, static_cast<void*>(®s), static_cast<void*>(reinterpret_cast<char*>(®s) + regSize));361 markConservatively(conservativeSet, static_cast<void*>(®s), static_cast<void*>(reinterpret_cast<char*>(®s) + regSize)); 362 362 363 363 void* stackPointer = otherThreadStackPointer(regs); 364 m _heap->markConservatively(conservativeSet, stackPointer, thread->stackBase);364 markConservatively(conservativeSet, stackPointer, thread->stackBase); 365 365 366 366 resumeThread(thread->platformThread); … … 398 398 } 399 399 400 inline bool isPointerAligned(void* p) 401 { 402 return (((intptr_t)(p) & (sizeof(char*) - 1)) == 0); 403 } 404 405 void MachineStackMarker::markConservatively(ConservativeSet& conservativeSet, void* start, void* end) 406 { 407 #if OS(WINCE) 408 if (start > end) { 409 void* tmp = start; 410 start = end; 411 end = tmp; 412 } 413 #else 414 ASSERT(start <= end); 415 #endif 416 417 ASSERT((static_cast<char*>(end) - static_cast<char*>(start)) < 0x1000000); 418 ASSERT(isPointerAligned(start)); 419 ASSERT(isPointerAligned(end)); 420 421 char** p = static_cast<char**>(start); 422 char** e = static_cast<char**>(end); 423 424 while (p != e) { 425 char* x = *p++; 426 if (!m_heap->contains(x)) 427 continue; 428 conservativeSet.add(reinterpret_cast<JSCell*>(x)); 429 } 430 } 431 400 432 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/MachineStackMarker.h
r76331 r76425 42 42 43 43 void markMachineStackConservatively(ConservativeSet&); 44 void markConservatively(ConservativeSet&, void* start, void* end); 44 45 45 46 #if ENABLE(JSC_MULTIPLE_THREADS) -
trunk/Source/JavaScriptCore/runtime/MarkStack.h
r76331 r76425 28 28 29 29 #include "JSValue.h" 30 #include <wtf/ HashSet.h>30 #include <wtf/Vector.h> 31 31 #include <wtf/Noncopyable.h> 32 32 #include <wtf/OSAllocator.h> … … 191 191 class ConservativeSet { 192 192 public: 193 void add(JSCell* cell) { m_ set.add(cell); }193 void add(JSCell* cell) { m_vector.append(cell); } 194 194 void mark(MarkStack& markStack) 195 195 { 196 HashSet<JSCell*>::iterator end = m_set.end(); 197 for (HashSet<JSCell*>::iterator it = m_set.begin(); it != end; ++it) 198 markStack.append(*it); 196 for (size_t i = 0; i < m_vector.size(); ++i) 197 markStack.append(m_vector[i]); 199 198 } 200 199 201 200 private: 202 HashSet<JSCell*> m_set;201 Vector<JSCell*, 64> m_vector; 203 202 }; 204 203 } -
trunk/Source/JavaScriptCore/runtime/MarkedSpace.cpp
r76331 r76425 201 201 } 202 202 203 inline bool isPointerAligned(void* p) 204 { 205 return (((intptr_t)(p) & (sizeof(char*) - 1)) == 0); 206 } 207 208 // Cell size needs to be a power of two for isPossibleCell to be valid. 209 COMPILE_ASSERT(sizeof(CollectorCell) % 2 == 0, Collector_cell_size_is_power_of_two); 210 211 static inline bool isCellAligned(void *p) 212 { 213 return (((intptr_t)(p) & CELL_MASK) == 0); 214 } 215 216 static inline bool isPossibleCell(void* p) 217 { 218 return isCellAligned(p) && p; 219 } 220 221 void MarkedSpace::markConservatively(ConservativeSet& conservativeSet, void* start, void* end) 222 { 223 #if OS(WINCE) 224 if (start > end) { 225 void* tmp = start; 226 start = end; 227 end = tmp; 228 } 229 #else 230 ASSERT(start <= end); 231 #endif 232 233 ASSERT((static_cast<char*>(end) - static_cast<char*>(start)) < 0x1000000); 234 ASSERT(isPointerAligned(start)); 235 ASSERT(isPointerAligned(end)); 236 237 char** p = static_cast<char**>(start); 238 char** e = static_cast<char**>(end); 239 240 while (p != e) { 241 char* x = *p++; 242 if (isPossibleCell(x)) { 243 uintptr_t xAsBits = reinterpret_cast<uintptr_t>(x); 244 xAsBits &= CELL_ALIGN_MASK; 245 246 uintptr_t offset = xAsBits & BLOCK_OFFSET_MASK; 247 const size_t lastCellOffset = sizeof(CollectorCell) * (CELLS_PER_BLOCK - 1); 248 if (offset > lastCellOffset) 249 continue; 250 251 CollectorBlock* blockAddr = reinterpret_cast<CollectorBlock*>(xAsBits - offset); 252 size_t usedBlocks = m_heap.usedBlocks; 253 for (size_t block = 0; block < usedBlocks; block++) { 254 if (m_heap.collectorBlock(block) != blockAddr) 255 continue; 256 257 // x is a pointer into the heap. Now, verify that the cell it 258 // points to is live. (If the cell is dead, we must not mark it, 259 // since that would revive it in a zombie state.) 260 if (block < m_heap.nextBlock) { 261 conservativeSet.add(reinterpret_cast<JSCell*>(xAsBits)); 262 break; 263 } 264 265 size_t cellOffset = offset / CELL_SIZE; 266 267 if (block == m_heap.nextBlock && cellOffset < m_heap.nextCell) { 268 conservativeSet.add(reinterpret_cast<JSCell*>(xAsBits)); 269 break; 270 } 271 272 if (blockAddr->marked.get(cellOffset)) { 273 conservativeSet.add(reinterpret_cast<JSCell*>(xAsBits)); 274 break; 275 } 276 } 277 } 278 } 203 bool MarkedSpace::containsSlowCase(void* x) 204 { 205 uintptr_t xAsBits = reinterpret_cast<uintptr_t>(x); 206 xAsBits &= CELL_ALIGN_MASK; 207 208 uintptr_t offset = xAsBits & BLOCK_OFFSET_MASK; 209 const size_t lastCellOffset = sizeof(CollectorCell) * (CELLS_PER_BLOCK - 1); 210 if (offset > lastCellOffset) 211 return false; 212 213 CollectorBlock* blockAddr = reinterpret_cast<CollectorBlock*>(xAsBits - offset); 214 size_t usedBlocks = m_heap.usedBlocks; 215 for (size_t block = 0; block < usedBlocks; block++) { 216 if (m_heap.collectorBlock(block) != blockAddr) 217 continue; 218 219 // x is a pointer into the heap. Now, verify that the cell it 220 // points to is live. (If the cell is dead, we must not mark it, 221 // since that would revive it in a zombie state.) 222 if (block < m_heap.nextBlock) 223 return true; 224 225 size_t cellOffset = offset / CELL_SIZE; 226 227 if (block == m_heap.nextBlock && cellOffset < m_heap.nextCell) 228 return true; 229 230 return blockAddr->marked.get(cellOffset); 231 } 232 233 return false; 279 234 } 280 235 -
trunk/Source/JavaScriptCore/runtime/MarkedSpace.h
r76331 r76425 86 86 WeakGCHandle* addWeakGCHandle(JSCell*); 87 87 88 void markConservatively(ConservativeSet&, void* start, void* end); 89 90 static bool isNumber(JSCell*); 91 88 bool contains(void*); 89 bool containsSlowCase(void*); 90 bool isCellAligned(void*); 91 bool isPossibleCell(void*); 92 92 93 LiveObjectIterator primaryHeapBegin(); 93 94 LiveObjectIterator primaryHeapEnd(); … … 218 219 } 219 220 221 // Cell size needs to be a power of two for isPossibleCell to be valid. 222 COMPILE_ASSERT(sizeof(CollectorCell) % 2 == 0, Collector_cell_size_is_power_of_two); 223 224 inline bool MarkedSpace::isCellAligned(void *p) 225 { 226 return (((intptr_t)(p) & CELL_MASK) == 0); 227 } 228 229 inline bool MarkedSpace::isPossibleCell(void* p) 230 { 231 return isCellAligned(p) && p; 232 } 233 234 inline bool MarkedSpace::contains(void* x) 235 { 236 if (!isPossibleCell(x)) 237 return false; 238 239 return containsSlowCase(x); 240 } 241 220 242 } // namespace JSC 221 243 -
trunk/Source/JavaScriptCore/wtf/HashSet.h
r76248 r76425 176 176 177 177 template<typename T, typename U, typename V> 178 pair<typename HashSet<T, U, V>::iterator, bool> HashSet<T, U, V>::add(const ValueType& value)178 inline pair<typename HashSet<T, U, V>::iterator, bool> HashSet<T, U, V>::add(const ValueType& value) 179 179 { 180 180 return m_impl.add(value); … … 183 183 template<typename Value, typename HashFunctions, typename Traits> 184 184 template<typename T, typename HashTranslator> 185 pair<typename HashSet<Value, HashFunctions, Traits>::iterator, bool>185 inline pair<typename HashSet<Value, HashFunctions, Traits>::iterator, bool> 186 186 HashSet<Value, HashFunctions, Traits>::add(const T& value) 187 187 {
Note: See TracChangeset
for help on using the changeset viewer.