Changeset 64849 in webkit
- Timestamp:
- Aug 6, 2010, 7:55:54 AM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/Android.mk
r64106 r64849 97 97 runtime/FunctionConstructor.cpp \ 98 98 runtime/FunctionPrototype.cpp \ 99 runtime/GCHandle.cpp \ 99 100 runtime/GetterSetter.cpp \ 100 101 runtime/GlobalEvalFunction.cpp \ -
trunk/JavaScriptCore/ChangeLog
r64842 r64849 1 2010-08-06 Nathan Lawrence <[email protected]> 2 3 Reviewed by Geoffrey Garen. 4 5 https://bugs.webkit.org/show_bug.cgi?id=43207 6 7 WeakGCPtr's should instead of directly pointing to the GC'd object 8 should be directed to an array of pointers that can be updated for 9 movable objects. 10 11 * Android.mk: 12 * GNUmakefile.am: 13 * JavaScriptCore.exp: 14 * JavaScriptCore.gypi: 15 * JavaScriptCore.pro: 16 * JavaScriptCore.xcodeproj/project.pbxproj: 17 * runtime/Collector.cpp: 18 (JSC::Heap::destroy): 19 (JSC::Heap::allocateBlock): 20 (JSC::Heap::freeBlock): 21 (JSC::Heap::updateWeakGCHandles): 22 (JSC::WeakGCHandlePool::update): 23 (JSC::Heap::addWeakGCHandle): 24 (JSC::Heap::markRoots): 25 * runtime/Collector.h: 26 (JSC::Heap::weakGCHandlePool): 27 * runtime/GCHandle.cpp: Added. 28 (JSC::WeakGCHandle::pool): 29 (JSC::WeakGCHandlePool::WeakGCHandlePool): 30 (JSC::WeakGCHandlePool::allocate): 31 (JSC::WeakGCHandlePool::free): 32 (JSC::WeakGCHandlePool::operator new): 33 * runtime/GCHandle.h: Added. 34 (JSC::WeakGCHandle::isValidPtr): 35 (JSC::WeakGCHandle::isPtr): 36 (JSC::WeakGCHandle::isNext): 37 (JSC::WeakGCHandle::invalidate): 38 (JSC::WeakGCHandle::get): 39 (JSC::WeakGCHandle::set): 40 (JSC::WeakGCHandle::getNextInFreeList): 41 (JSC::WeakGCHandle::setNextInFreeList): 42 (JSC::WeakGCHandlePool::isFull): 43 * runtime/WeakGCPtr.h: 44 (JSC::WeakGCPtr::WeakGCPtr): 45 (JSC::WeakGCPtr::~WeakGCPtr): 46 (JSC::WeakGCPtr::get): 47 (JSC::WeakGCPtr::clear): 48 (JSC::WeakGCPtr::assign): 49 (JSC::get): 50 1 51 2010-08-06 Tor Arne Vestbø <[email protected]> 2 52 -
trunk/JavaScriptCore/GNUmakefile.am
r64759 r64849 269 269 JavaScriptCore/runtime/GCActivityCallback.cpp \ 270 270 JavaScriptCore/runtime/GCActivityCallback.h \ 271 JavaScriptCore/runtime/GCHandle.cpp \ 272 JavaScriptCore/runtime/GCHandle.h \ 271 273 JavaScriptCore/runtime/GetterSetter.cpp \ 272 274 JavaScriptCore/runtime/GetterSetter.h \ -
trunk/JavaScriptCore/JavaScriptCore.exp
r64585 r64849 142 142 __ZN3JSC12StringObject4infoE 143 143 __ZN3JSC12StringObjectC2EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEERKNS_7UStringE 144 __ZN3JSC12WeakGCHandle4poolEv 144 145 __ZN3JSC12jsNumberCellEPNS_9ExecStateEd 145 146 __ZN3JSC12nonInlineNaNEv … … 172 173 __ZN3JSC16JSVariableObject14symbolTableGetERKNS_10IdentifierERNS_18PropertyDescriptorE 173 174 __ZN3JSC16JSVariableObject19getOwnPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayENS_15EnumerationModeE 175 __ZN3JSC16WeakGCHandlePool4freeEPNS_12WeakGCHandleE 174 176 __ZN3JSC16createRangeErrorEPNS_9ExecStateERKNS_7UStringE 175 177 __ZN3JSC16throwSyntaxErrorEPNS_9ExecStateE … … 202 204 __ZN3JSC3NaNE 203 205 __ZN3JSC4Heap14primaryHeapEndEv 206 __ZN3JSC4Heap15addWeakGCHandleEPNS_6JSCellE 204 207 __ZN3JSC4Heap15recordExtraCostEm 205 208 __ZN3JSC4Heap16objectTypeCountsEv -
trunk/JavaScriptCore/JavaScriptCore.gypi
r64696 r64849 218 218 'runtime/GCActivityCallback.cpp', 219 219 'runtime/GCActivityCallback.h', 220 'runtime/GCHandle.cpp', 221 'runtime/GCHandle.h', 220 222 'runtime/GetterSetter.cpp', 221 223 'runtime/GetterSetter.h', -
trunk/JavaScriptCore/JavaScriptCore.pro
r64624 r64849 141 141 runtime/FunctionPrototype.cpp \ 142 142 runtime/GCActivityCallback.cpp \ 143 runtime/GCHandle.cpp \ 143 144 runtime/GetterSetter.cpp \ 144 145 runtime/GlobalEvalFunction.cpp \ -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r64801 r64849 513 513 DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; }; 514 514 DD377CBC12072C18006A2517 /* Bitmap.h in Headers */ = {isa = PBXBuildFile; fileRef = DD377CBB12072C18006A2517 /* Bitmap.h */; settings = {ATTRIBUTES = (Private, ); }; }; 515 DDE82AD31209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; }; 516 DDE82AD41209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; }; 517 DDE82AD51209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; }; 518 DDE82AD61209D955005C1756 /* GCHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE82AD21209D955005C1756 /* GCHandle.h */; }; 519 DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; }; 520 DDE82AD81209D955005C1756 /* GCHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE82AD21209D955005C1756 /* GCHandle.h */; settings = {ATTRIBUTES = (Private, ); }; }; 515 521 DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */; }; 516 522 DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDF7ABD311F60ED200108E36 /* GCActivityCallbackCF.cpp */; }; … … 1059 1065 DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlignedMemoryAllocator.h; sourceTree = "<group>"; }; 1060 1066 DD377CBB12072C18006A2517 /* Bitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bitmap.h; sourceTree = "<group>"; }; 1067 DDE82AD11209D955005C1756 /* GCHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCHandle.cpp; sourceTree = "<group>"; }; 1068 DDE82AD21209D955005C1756 /* GCHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCHandle.h; sourceTree = "<group>"; }; 1061 1069 DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCActivityCallback.h; sourceTree = "<group>"; }; 1062 1070 DDF7ABD311F60ED200108E36 /* GCActivityCallbackCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCActivityCallbackCF.cpp; sourceTree = "<group>"; }; … … 1625 1633 F692A85C0255597D01FF60F7 /* FunctionPrototype.cpp */, 1626 1634 F692A85D0255597D01FF60F7 /* FunctionPrototype.h */, 1635 DDE82AD11209D955005C1756 /* GCHandle.cpp */, 1636 DDE82AD21209D955005C1756 /* GCHandle.h */, 1627 1637 BC02E9B80E184545000F9297 /* GetterSetter.cpp */, 1628 1638 BC337BDE0E1AF0B80076918A /* GetterSetter.h */, … … 1913 1923 1440074A0A536CC20005F061 /* NodeList.h in Headers */, 1914 1924 DD2724681208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */, 1925 DDE82AD61209D955005C1756 /* GCHandle.h in Headers */, 1915 1926 ); 1916 1927 runOnlyForDeploymentPostprocessing = 0; … … 2215 2226 DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */, 2216 2227 DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */, 2228 DDE82AD81209D955005C1756 /* GCHandle.h in Headers */, 2217 2229 ); 2218 2230 runOnlyForDeploymentPostprocessing = 0; … … 2476 2488 1440063F0A53598A0005F061 /* Node.c in Sources */, 2477 2489 1440074B0A536CC20005F061 /* NodeList.c in Sources */, 2490 DDE82AD51209D955005C1756 /* GCHandle.cpp in Sources */, 2478 2491 ); 2479 2492 runOnlyForDeploymentPostprocessing = 0; … … 2484 2497 files = ( 2485 2498 1440F6100A4F85670005F061 /* testapi.c in Sources */, 2499 DDE82AD41209D955005C1756 /* GCHandle.cpp in Sources */, 2486 2500 ); 2487 2501 runOnlyForDeploymentPostprocessing = 0; … … 2663 2677 DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */, 2664 2678 8627E5EB11F1281900A313B5 /* PageAllocation.cpp in Sources */, 2679 DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */, 2665 2680 ); 2666 2681 runOnlyForDeploymentPostprocessing = 0; … … 2671 2686 files = ( 2672 2687 932F5BDD0822A1C700736975 /* jsc.cpp in Sources */, 2688 DDE82AD31209D955005C1756 /* GCHandle.cpp in Sources */, 2673 2689 ); 2674 2690 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/runtime/Collector.cpp
r64695 r64849 171 171 freeBlocks(); 172 172 173 for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i) 174 m_weakGCHandlePools[i].deallocate(); 175 173 176 #if ENABLE(JSC_MULTIPLE_THREADS) 174 177 if (m_currentThreadRegistrar) { … … 190 193 NEVER_INLINE CollectorBlock* Heap::allocateBlock() 191 194 { 192 Aligned Block allocation = m_blockallocator.allocate();195 AlignedCollectorBlock allocation = m_blockallocator.allocate(); 193 196 CollectorBlock* block = static_cast<CollectorBlock*>(allocation.base()); 194 197 if (!block) … … 208 211 size_t numBlocks = m_heap.numBlocks; 209 212 if (m_heap.usedBlocks == numBlocks) { 210 static const size_t maxNumBlocks = ULONG_MAX / sizeof(Aligned Block) / GROWTH_FACTOR;213 static const size_t maxNumBlocks = ULONG_MAX / sizeof(AlignedCollectorBlock) / GROWTH_FACTOR; 211 214 if (numBlocks > maxNumBlocks) 212 215 CRASH(); 213 216 numBlocks = max(MIN_ARRAY_SIZE, numBlocks * GROWTH_FACTOR); 214 217 m_heap.numBlocks = numBlocks; 215 m_heap.blocks = static_cast<Aligned Block*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(AlignedBlock)));218 m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(AlignedCollectorBlock))); 216 219 } 217 220 m_heap.blocks[m_heap.usedBlocks++] = allocation; … … 236 239 if (m_heap.numBlocks > MIN_ARRAY_SIZE && m_heap.usedBlocks < m_heap.numBlocks / LOW_WATER_FACTOR) { 237 240 m_heap.numBlocks = m_heap.numBlocks / GROWTH_FACTOR; 238 m_heap.blocks = static_cast<Aligned Block*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(AlignedBlock)));241 m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(AlignedCollectorBlock))); 239 242 } 240 243 } … … 907 910 } 908 911 912 void Heap::updateWeakGCHandles() 913 { 914 for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i) 915 weakGCHandlePool(i)->update(); 916 } 917 918 void WeakGCHandlePool::update() 919 { 920 for (unsigned i = 1; i < WeakGCHandlePool::numPoolEntries; ++i) { 921 if (m_entries[i].isValidPtr()) { 922 JSCell* cell = m_entries[i].get(); 923 if (!cell || !Heap::isCellMarked(cell)) 924 m_entries[i].invalidate(); 925 } 926 } 927 } 928 929 WeakGCHandle* Heap::addWeakGCHandle(JSCell* ptr) 930 { 931 for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i) 932 if (!weakGCHandlePool(i)->isFull()) 933 return weakGCHandlePool(i)->allocate(ptr); 934 935 AlignedMemory<WeakGCHandlePool::poolSize> allocation = m_weakGCHandlePoolAllocator.allocate(); 936 m_weakGCHandlePools.append(allocation); 937 938 WeakGCHandlePool* pool = new (allocation) WeakGCHandlePool(); 939 return pool->allocate(ptr); 940 } 941 909 942 void Heap::protect(JSValue k) 910 943 { … … 1043 1076 markStack.compact(); 1044 1077 1078 updateWeakGCHandles(); 1079 1045 1080 m_heap.operationInProgress = NoOperation; 1046 1081 } -
trunk/JavaScriptCore/runtime/Collector.h
r64695 r64849 24 24 25 25 #include "AlignedMemoryAllocator.h" 26 #include "GCHandle.h" 26 27 #include <stddef.h> 27 28 #include <string.h> … … 63 64 #endif 64 65 65 typedef AlignedMemoryAllocator<BLOCK_SIZE> AlignedAllocator;66 typedef AlignedMemory<BLOCK_SIZE> Aligned Block;66 typedef AlignedMemoryAllocator<BLOCK_SIZE> CollectorBlockAllocator; 67 typedef AlignedMemory<BLOCK_SIZE> AlignedCollectorBlock; 67 68 68 69 struct CollectorHeap { 69 70 size_t nextBlock; 70 71 size_t nextCell; 71 Aligned Block* blocks;72 AlignedCollectorBlock* blocks; 72 73 73 74 void* nextNumber; … … 131 132 static bool isCellMarked(const JSCell*); 132 133 static void markCell(JSCell*); 134 135 WeakGCHandle* addWeakGCHandle(JSCell*); 133 136 134 137 void markConservatively(MarkStack&, void* start, void* end); … … 173 176 void markStackObjectsConservatively(MarkStack&); 174 177 178 void updateWeakGCHandles(); 179 WeakGCHandlePool* weakGCHandlePool(size_t index); 180 175 181 typedef HashCountedSet<JSCell*> ProtectCountSet; 176 182 … … 178 184 179 185 ProtectCountSet m_protectedValues; 186 WTF::Vector<AlignedMemory<WeakGCHandlePool::poolSize> > m_weakGCHandlePools; 180 187 181 188 HashSet<MarkedArgumentBuffer*>* m_markListSet; … … 195 202 196 203 // Allocates collector blocks with correct alignment 197 AlignedAllocator m_blockallocator; 204 CollectorBlockAllocator m_blockallocator; 205 WeakGCHandlePool::Allocator m_weakGCHandlePoolAllocator; 198 206 199 207 JSGlobalData* m_globalData; … … 303 311 return result; 304 312 } 313 314 315 inline WeakGCHandlePool* Heap::weakGCHandlePool(size_t index) 316 { 317 return static_cast<WeakGCHandlePool*>(m_weakGCHandlePools[index].base()); 318 } 305 319 } // namespace JSC 306 320 -
trunk/JavaScriptCore/runtime/WeakGCPtr.h
r58267 r64849 28 28 29 29 #include "Collector.h" 30 #include "GCHandle.h" 30 31 #include <wtf/Noncopyable.h> 31 32 … … 35 36 template <typename T> class WeakGCPtr : Noncopyable { 36 37 public: 37 WeakGCPtr() : m_ptr(0) { } 38 WeakGCPtr() 39 : m_ptr(0) 40 { 41 } 42 38 43 WeakGCPtr(T* ptr) { assign(ptr); } 44 45 ~WeakGCPtr() 46 { 47 if (m_ptr) 48 m_ptr->pool()->free(m_ptr); 49 } 39 50 40 51 T* get() const 41 52 { 42 if ( !m_ptr || !Heap::isCellMarked(m_ptr))43 return 0;44 return m_ptr;53 if (m_ptr && m_ptr->isValidPtr()) 54 return static_cast<T*>(m_ptr->get()); 55 return 0; 45 56 } 46 57 47 bool clear(JSCell* p tr)58 bool clear(JSCell* p) 48 59 { 49 if (ptr == m_ptr) { 50 m_ptr = 0; 51 return true; 52 } 53 return false; 60 if (!m_ptr || m_ptr->get() != p) 61 return false; 62 63 m_ptr->pool()->free(m_ptr); 64 m_ptr = 0; 65 return true; 54 66 } 55 67 … … 63 75 operator bool() const { return m_ptr; } 64 76 #else 65 typedef T* WeakGCPtr::*UnspecifiedBoolType;77 typedef WeakGCHandle* WeakGCPtr::*UnspecifiedBoolType; 66 78 operator UnspecifiedBoolType() const { return get() ? &WeakGCPtr::m_ptr : 0; } 67 79 #endif … … 74 86 75 87 private: 76 void assign( T* ptr)88 void assign(JSCell* ptr) 77 89 { 78 90 ASSERT(ptr); 79 Heap::markCell(ptr); 80 m_ptr = ptr; 91 if (m_ptr) 92 m_ptr->set(ptr); 93 else 94 m_ptr = Heap::heap(ptr)->addWeakGCHandle(ptr); 81 95 } 82 96 83 T* m_ptr;97 WeakGCHandle* m_ptr; 84 98 }; 85 99 … … 130 144 } 131 145 132 template <typename T> inline T* get Ptr(const WeakGCPtr<T>& p)146 template <typename T> inline T* get(const WeakGCPtr<T>& p) 133 147 { 134 148 return p.get();
Note:
See TracChangeset
for help on using the changeset viewer.