Changeset 34947 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Jul 2, 2008, 12:00:53 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r34907 r34947 24 24 #include "ExecState.h" 25 25 #include "JSGlobalObject.h" 26 #include "JSLock.h" 26 27 #include "JSString.h" 27 28 #include "JSValue.h" … … 91 92 static void freeHeap(CollectorHeap*); 92 93 93 Heap::Heap( )94 Heap::Heap(bool isShared) 94 95 : m_markListSet(0) 96 , m_isShared(isShared) 95 97 { 96 98 memset(&primaryHeap, 0, sizeof(CollectorHeap)); … … 100 102 Heap::~Heap() 101 103 { 102 JSLock lock ;104 JSLock lock(false); 103 105 104 106 delete m_markListSet; … … 439 441 // Can't use JSLock convenience object here because we don't want to re-register 440 442 // an exiting thread. 441 JSLock::lock(); 443 // JSLock is only used for code simplicity here, as we only need to protect registeredThreads 444 // list manipulation, not JS data structures. 445 JSLock::lock(true); 442 446 443 447 if (registeredThreads == thread) { … … 456 460 } 457 461 458 JSLock::unlock( );462 JSLock::unlock(true); 459 463 460 464 delete thread; … … 468 472 void Heap::registerThread() 469 473 { 474 // Since registerThread() is only called when using a shared heap, these locks will be real. 470 475 ASSERT(JSLock::lockCount() > 0); 471 476 ASSERT(JSLock::currentThreadIsHoldingLock()); … … 729 734 #if USE(MULTIPLE_THREADS) 730 735 731 if ( this == JSGlobalData::sharedInstance().heap) {736 if (m_isShared) { 732 737 733 738 #ifndef NDEBUG … … 737 742 fastMallocForbid(); 738 743 #endif 744 // It is safe to access the registeredThreads list, because we earlier asserted that locks are being held, 745 // and since this is a shared heap, they are real locks. 739 746 for (Thread* thread = registeredThreads; thread != NULL; thread = thread->next) { 740 747 if (!pthread_equal(thread->posixThread, pthread_self())) … … 748 755 } 749 756 757 void Heap::setGCProtectNeedsLocking() 758 { 759 // Most clients do not need to call this, with the notable exception of WebCore. 760 // Clients that use shared heap have JSLock protection, while others are not supposed 761 // to migrate JS objects between threads. WebCore violates this contract in Database code, 762 // which calls gcUnprotect from a secondary thread. 763 if (!m_protectedValuesMutex) 764 m_protectedValuesMutex.set(new Mutex); 765 } 766 750 767 void Heap::protect(JSValue* k) 751 768 { 752 769 ASSERT(k); 753 ASSERT(JSLock::lockCount() > 0); 754 ASSERT(JSLock::currentThreadIsHoldingLock()); 770 ASSERT(JSLock::currentThreadIsHoldingLock() || !m_isShared); 755 771 756 772 if (JSImmediate::isImmediate(k)) 757 773 return; 758 774 759 protectedValues.add(k->asCell()); 775 if (m_protectedValuesMutex) 776 m_protectedValuesMutex->lock(); 777 778 m_protectedValues.add(k->asCell()); 779 780 if (m_protectedValuesMutex) 781 m_protectedValuesMutex->unlock(); 760 782 } 761 783 … … 763 785 { 764 786 ASSERT(k); 765 ASSERT(JSLock::lockCount() > 0); 766 ASSERT(JSLock::currentThreadIsHoldingLock()); 787 ASSERT(JSLock::currentThreadIsHoldingLock() || !m_isShared); 767 788 768 789 if (JSImmediate::isImmediate(k)) 769 790 return; 770 791 771 protectedValues.remove(k->asCell()); 792 if (m_protectedValuesMutex) 793 m_protectedValuesMutex->lock(); 794 795 m_protectedValues.remove(k->asCell()); 796 797 if (m_protectedValuesMutex) 798 m_protectedValuesMutex->unlock(); 772 799 } 773 800 … … 781 808 void Heap::markProtectedObjects() 782 809 { 783 ProtectCountSet::iterator end = protectedValues.end(); 784 for (ProtectCountSet::iterator it = protectedValues.begin(); it != end; ++it) { 810 if (m_protectedValuesMutex) 811 m_protectedValuesMutex->lock(); 812 813 ProtectCountSet::iterator end = m_protectedValues.end(); 814 for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it) { 785 815 JSCell* val = it->first; 786 816 if (!val->marked()) 787 817 val->mark(); 788 818 } 819 820 if (m_protectedValuesMutex) 821 m_protectedValuesMutex->unlock(); 789 822 } 790 823 … … 941 974 size_t Heap::protectedGlobalObjectCount() 942 975 { 976 if (m_protectedValuesMutex) 977 m_protectedValuesMutex->lock(); 978 943 979 size_t count = 0; 944 980 if (JSGlobalObject* head = JSGlobalData::threadInstance().head) { 945 981 JSGlobalObject* o = head; 946 982 do { 947 if ( protectedValues.contains(o))983 if (m_protectedValues.contains(o)) 948 984 ++count; 949 985 o = o->next(); 950 986 } while (o != head); 951 987 } 988 989 if (m_protectedValuesMutex) 990 m_protectedValuesMutex->unlock(); 991 952 992 return count; 953 993 } … … 955 995 size_t Heap::protectedObjectCount() 956 996 { 957 return protectedValues.size(); 997 if (m_protectedValuesMutex) 998 m_protectedValuesMutex->lock(); 999 1000 size_t result = m_protectedValues.size(); 1001 1002 if (m_protectedValuesMutex) 1003 m_protectedValuesMutex->unlock(); 1004 1005 return result; 958 1006 } 959 1007 … … 995 1043 HashCountedSet<const char*>* counts = new HashCountedSet<const char*>; 996 1044 997 ProtectCountSet::iterator end = protectedValues.end(); 998 for (ProtectCountSet::iterator it = protectedValues.begin(); it != end; ++it) 1045 if (m_protectedValuesMutex) 1046 m_protectedValuesMutex->lock(); 1047 1048 ProtectCountSet::iterator end = m_protectedValues.end(); 1049 for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it) 999 1050 counts->add(typeName(it->first)); 1000 1051 1052 if (m_protectedValuesMutex) 1053 m_protectedValuesMutex->unlock(); 1054 1001 1055 return counts; 1002 1056 }
Note:
See TracChangeset
for help on using the changeset viewer.