Changeset 34977 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 3, 2008, 12:44:43 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSBase.cpp
r34947 r34977 89 89 // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context). 90 90 91 // FIXME: It would be good to avoid creating a JSGlobalData instance if it didn't exist for this thread yet. 92 Heap* heap = JSGlobalData::threadInstance().heap; 93 if (!heap->isBusy()) 94 heap->collect(); 91 if (JSGlobalData::threadInstanceExists()) { 92 Heap* heap = JSGlobalData::threadInstance().heap; 93 if (!heap->isBusy()) 94 heap->collect(); 95 } 95 96 96 97 JSLock lock(true); 97 98 98 // FIXME: Similarly, we shouldn't create a shared instance here. 99 heap = JSGlobalData::sharedInstance().heap; 100 if (!heap->isBusy()) 101 heap->collect(); 99 if (JSGlobalData::sharedInstanceExists()) { 100 Heap* heap = JSGlobalData::sharedInstance().heap; 101 if (!heap->isBusy()) 102 heap->collect(); 103 } 102 104 103 105 // FIXME: Perhaps we should trigger a second mark and sweep -
trunk/JavaScriptCore/ChangeLog
r34974 r34977 1 2008-07-02 Alexey Proskuryakov <[email protected]> 2 3 Reviewed by Geoff. 4 5 Don't create unnecessary JSGlobalData instances. 6 7 * kjs/JSGlobalData.h: 8 * kjs/JSGlobalData.cpp: 9 (KJS::JSGlobalData::threadInstanceExists): 10 (KJS::JSGlobalData::sharedInstanceExists): 11 (KJS::JSGlobalData::threadInstance): 12 (KJS::JSGlobalData::sharedInstance): 13 (KJS::JSGlobalData::threadInstanceInternal): 14 (KJS::JSGlobalData::sharedInstanceInternal): 15 Added methods to query instance existence. 16 17 * kjs/InitializeThreading.cpp: 18 (KJS::initializeThreadingOnce): 19 Initialize thread instance static in a new way. 20 21 * API/JSBase.cpp: 22 (JSGarbageCollect): 23 * kjs/collector.cpp: 24 (KJS::Heap::collect): 25 Check for instance existence before accessing it. 26 1 27 2008-07-02 Geoffrey Garen <[email protected]> 2 28 -
trunk/JavaScriptCore/kjs/InitializeThreading.cpp
r34810 r34977 49 49 #if USE(MULTIPLE_THREADS) 50 50 s_dtoaP5Mutex = new Mutex; 51 JSGlobalData::threadInstance ();51 JSGlobalData::threadInstanceExists(); 52 52 UString::null(); 53 53 initDateMath(); -
trunk/JavaScriptCore/kjs/JSGlobalData.cpp
r34974 r34977 32 32 #include "collector.h" 33 33 #include "CommonIdentifiers.h" 34 #include "JSLock.h" 34 35 #include "lexer.h" 35 36 #include "list.h" … … 120 121 } 121 122 123 bool JSGlobalData::threadInstanceExists() 124 { 125 return threadInstanceInternal(); 126 } 127 128 bool JSGlobalData::sharedInstanceExists() 129 { 130 return sharedInstanceInternal(); 131 } 132 122 133 JSGlobalData& JSGlobalData::threadInstance() 123 134 { 124 #if USE(MULTIPLE_THREADS) 125 static ThreadSpecific<JSGlobalData> sharedInstance; 126 return *sharedInstance; 127 #else 128 static JSGlobalData sharedInstance; 129 return sharedInstance; 130 #endif 135 JSGlobalData*& instance = threadInstanceInternal(); 136 if (!instance) 137 instance = new JSGlobalData; 138 return *instance; 131 139 } 132 140 133 141 JSGlobalData& JSGlobalData::sharedInstance() 134 142 { 143 JSGlobalData*& instance = sharedInstanceInternal(); 144 if (!instance) 145 instance = new JSGlobalData(true); 146 return *instance; 147 } 148 149 JSGlobalData*& JSGlobalData::threadInstanceInternal() 150 { 135 151 #if USE(MULTIPLE_THREADS) 136 MutexLocker locker(*atomicallyInitializedStaticMutex); 152 static ThreadSpecific<DataInstance> threadInstance; 153 return *threadInstance; 154 #else 155 static JSGlobalData threadInstance; 156 return &threadInstance; 137 157 #endif 158 } 159 160 JSGlobalData*& JSGlobalData::sharedInstanceInternal() 161 { 162 ASSERT(JSLock::currentThreadIsHoldingLock()); 138 163 static JSGlobalData* sharedInstance; 139 if (!sharedInstance) 140 sharedInstance = new JSGlobalData(true); 141 return *sharedInstance; 164 return sharedInstance; 142 165 } 143 166 -
trunk/JavaScriptCore/kjs/JSGlobalData.h
r34947 r34977 34 34 #include <wtf/HashSet.h> 35 35 #include <wtf/Noncopyable.h> 36 37 namespace WTF { 38 template<typename> class ThreadSpecific; 39 } 36 #include <wtf/OwnPtr.h> 40 37 41 38 namespace KJS { … … 56 53 // JavaScriptCore clients, which all share a single JSGlobalData, and thus cannot run concurrently. 57 54 struct JSGlobalData : Noncopyable { 55 static bool threadInstanceExists(); 56 static bool sharedInstanceExists(); 58 57 static JSGlobalData& threadInstance(); 59 58 static JSGlobalData& sharedInstance(); … … 85 84 86 85 private: 87 friend class WTF::ThreadSpecific<JSGlobalData>;88 89 86 JSGlobalData(bool isShared = false); 90 87 ~JSGlobalData(); 88 89 static JSGlobalData*& threadInstanceInternal(); 90 static JSGlobalData*& sharedInstanceInternal(); 91 92 struct DataInstance { 93 DataInstance() : m_data(0) {} 94 ~DataInstance() { delete m_data; } 95 operator JSGlobalData*&() { return m_data; } 96 97 JSGlobalData* m_data; 98 }; 91 99 }; 92 100 -
trunk/JavaScriptCore/kjs/collector.cpp
r34974 r34977 926 926 { 927 927 #ifndef NDEBUG 928 if (JSGlobalData::sharedInstance ().heap == this) {928 if (JSGlobalData::sharedInstanceExists() && JSGlobalData::sharedInstance().heap == this) { 929 929 ASSERT(JSLock::lockCount() > 0); 930 930 ASSERT(JSLock::currentThreadIsHoldingLock());
Note:
See TracChangeset
for help on using the changeset viewer.