Changeset 32822 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- May 2, 2008, 1:05:47 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/InitializeThreading.cpp
r32808 r32822 36 36 #include "JSGlobalObject.h" 37 37 #include "lexer.h" 38 #include "nodes.h" 38 39 #include "Parser.h" 39 40 #include "ustring.h" … … 59 60 JSGlobalObject::threadClassInfoHashTables(); 60 61 JSGlobalObject::head(); 62 initializeNodesThreading(); 61 63 #endif 62 64 } -
trunk/JavaScriptCore/kjs/nodes.cpp
r32807 r32822 42 42 #include <wtf/HashSet.h> 43 43 #include <wtf/MathExtras.h> 44 #if USE(MULTIPLE_THREADS) 45 #include <wtf/ThreadSpecific.h> 46 #endif 47 48 using namespace WTF; 44 49 45 50 namespace KJS { … … 118 123 #define LOG_CHANNEL_PREFIX Log 119 124 #endif 125 120 126 static WTFLogChannel LogKJSNodeLeaks = { 0x00000000, "", WTFLogChannelOn }; 121 127 … … 132 138 #endif 133 139 134 static HashSet<ParserRefCounted*>* newTrackedObjects; 135 static HashCountedSet<ParserRefCounted*>* trackedObjectExtraRefCounts; 140 static HashSet<ParserRefCounted*>* newTrackedObjects() 141 { 142 #if USE(MULTIPLE_THREADS) 143 static ThreadSpecific<HashSet<ParserRefCounted*> > sharedInstance; 144 return sharedInstance; 145 #else 146 static HashSet<ParserRefCounted*> sharedInstance; 147 return &sharedInstance; 148 #endif 149 } 150 151 static HashCountedSet<ParserRefCounted*>* trackedObjectExtraRefCounts() 152 { 153 #if USE(MULTIPLE_THREADS) 154 static ThreadSpecific<HashCountedSet<ParserRefCounted*> > sharedInstance; 155 return sharedInstance; 156 #else 157 static HashCountedSet<ParserRefCounted*> sharedInstance; 158 return &sharedInstance; 159 #endif 160 } 161 162 void initializeNodesThreading() 163 { 164 newTrackedObjects(); 165 trackedObjectExtraRefCounts(); 166 } 136 167 137 168 ParserRefCounted::ParserRefCounted() … … 140 171 ++ParserRefCountedCounter::count; 141 172 #endif 142 if (!newTrackedObjects) 143 newTrackedObjects = new HashSet<ParserRefCounted*>; 144 newTrackedObjects->add(this); 145 ASSERT(newTrackedObjects->contains(this)); 173 newTrackedObjects()->add(this); 174 ASSERT(newTrackedObjects()->contains(this)); 146 175 } 147 176 … … 155 184 void ParserRefCounted::ref() 156 185 { 186 HashSet<ParserRefCounted*>* localNewTrackedObjects = newTrackedObjects(); 187 157 188 // bumping from 0 to 1 is just removing from the new nodes set 158 if (newTrackedObjects) { 159 HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->find(this); 160 if (it != newTrackedObjects->end()) { 161 newTrackedObjects->remove(it); 162 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this)); 163 return; 164 } 165 } 166 167 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this)); 168 169 if (!trackedObjectExtraRefCounts) 170 trackedObjectExtraRefCounts = new HashCountedSet<ParserRefCounted*>; 171 trackedObjectExtraRefCounts->add(this); 189 HashSet<ParserRefCounted*>::iterator it = localNewTrackedObjects->find(this); 190 if (it != localNewTrackedObjects->end()) { 191 localNewTrackedObjects->remove(it); 192 ASSERT(!trackedObjectExtraRefCounts()->contains(this)); 193 return; 194 } 195 196 ASSERT(!localNewTrackedObjects->contains(this)); 197 198 trackedObjectExtraRefCounts()->add(this); 172 199 } 173 200 174 201 void ParserRefCounted::deref() 175 202 { 176 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this)); 177 178 if (!trackedObjectExtraRefCounts) { 179 delete this; 180 return; 181 } 182 183 HashCountedSet<ParserRefCounted*>::iterator it = trackedObjectExtraRefCounts->find(this); 184 if (it == trackedObjectExtraRefCounts->end()) 203 ASSERT(!newTrackedObjects()->contains(this)); 204 HashCountedSet<ParserRefCounted*>* localTrackedObjectExtraRefCounts = trackedObjectExtraRefCounts(); 205 206 HashCountedSet<ParserRefCounted*>::iterator it = localTrackedObjectExtraRefCounts->find(this); 207 if (it == localTrackedObjectExtraRefCounts->end()) 185 208 delete this; 186 209 else 187 trackedObjectExtraRefCounts->remove(it);210 localTrackedObjectExtraRefCounts->remove(it); 188 211 } 189 212 190 213 unsigned ParserRefCounted::refcount() 191 214 { 192 if (newTrackedObjects && newTrackedObjects->contains(this)) { 193 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this)); 215 HashCountedSet<ParserRefCounted*>* localTrackedObjectExtraRefCounts = trackedObjectExtraRefCounts(); 216 217 if (newTrackedObjects()->contains(this)) { 218 ASSERT(!localTrackedObjectExtraRefCounts->contains(this)); 194 219 return 0; 195 220 } 196 221 197 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this));198 199 if (! trackedObjectExtraRefCounts)222 ASSERT(!newTrackedObjects()->contains(this)); 223 224 if (!localTrackedObjectExtraRefCounts) 200 225 return 1; 201 226 202 return 1 + trackedObjectExtraRefCounts->count(this);227 return 1 + localTrackedObjectExtraRefCounts->count(this); 203 228 } 204 229 205 230 void ParserRefCounted::deleteNewObjects() 206 231 { 207 if (!newTrackedObjects) 208 return; 209 232 HashSet<ParserRefCounted*>* localNewTrackedObjects = newTrackedObjects(); 210 233 #ifndef NDEBUG 211 HashSet<ParserRefCounted*>::iterator end = newTrackedObjects->end();212 for (HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->begin(); it != end; ++it)213 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(*it));234 HashSet<ParserRefCounted*>::iterator end = localNewTrackedObjects->end(); 235 for (HashSet<ParserRefCounted*>::iterator it = localNewTrackedObjects->begin(); it != end; ++it) 236 ASSERT(!trackedObjectExtraRefCounts()->contains(*it)); 214 237 #endif 215 deleteAllValues(*newTrackedObjects); 216 delete newTrackedObjects; 217 newTrackedObjects = 0; 238 deleteAllValues(*localNewTrackedObjects); 239 localNewTrackedObjects->clear(); 218 240 } 219 241 -
trunk/JavaScriptCore/kjs/nodes.h
r31991 r32822 3010 3010 }; 3011 3011 3012 void initializeNodesThreading(); 3013 3012 3014 } // namespace KJS 3013 3015
Note:
See TracChangeset
for help on using the changeset viewer.