Changeset 34947 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 2, 2008, 12:00:53 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSBase.cpp
r34659 r34947 41 41 JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 42 42 { 43 JSLock lock;44 43 ExecState* exec = toJS(ctx); 44 JSLock lock(exec); 45 45 JSObject* jsThisObject = toJS(thisObject); 46 46 UString::Rep* scriptRep = toJS(script); … … 66 66 bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 67 67 { 68 JSLock lock;69 70 68 ExecState* exec = toJS(ctx); 69 JSLock lock(exec); 71 70 UString::Rep* scriptRep = toJS(script); 72 71 UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; … … 90 89 // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context). 91 90 92 JSLock lock;93 94 91 // FIXME: It would be good to avoid creating a JSGlobalData instance if it didn't exist for this thread yet. 95 92 Heap* heap = JSGlobalData::threadInstance().heap; 96 93 if (!heap->isBusy()) 97 94 heap->collect(); 95 96 JSLock lock(true); 98 97 99 98 // FIXME: Similarly, we shouldn't create a shared instance here. -
trunk/JavaScriptCore/API/JSCallbackConstructor.cpp
r34854 r34947 30 30 #include "APICast.h" 31 31 #include <kjs/JSGlobalObject.h> 32 #include <kjs/JSLock.h> 32 33 #include <kjs/ObjectPrototype.h> 33 34 #include <wtf/Vector.h> … … 69 70 arguments[i] = toRef(args[i]); 70 71 71 JSLock::DropAllLocks dropAllLocks ;72 JSLock::DropAllLocks dropAllLocks(exec); 72 73 return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 73 74 } -
trunk/JavaScriptCore/API/JSCallbackFunction.cpp
r34754 r34947 33 33 #include "FunctionPrototype.h" 34 34 #include <kjs/JSGlobalObject.h> 35 #include <kjs/JSLock.h> 35 36 #include <wtf/Vector.h> 36 37 … … 63 64 arguments[i] = toRef(args[i]); 64 65 65 JSLock::DropAllLocks dropAllLocks ;66 JSLock::DropAllLocks dropAllLocks(exec); 66 67 return toJS(static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 67 68 } -
trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h
r34754 r34947 30 30 #include "JSClassRef.h" 31 31 #include "JSGlobalObject.h" 32 #include "JSLock.h" 32 33 #include "JSObjectRef.h" 33 34 #include "JSString.h" … … 72 73 // initialize from base to derived 73 74 for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) { 74 JSLock::DropAllLocks dropAllLocks ;75 JSLock::DropAllLocks dropAllLocks(exec); 75 76 JSObjectInitializeCallback initialize = initRoutines[i]; 76 77 initialize(toRef(exec), toRef(this)); … … 110 111 // optional optimization to bypass getProperty in cases when we only need to know if the property exists 111 112 if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) { 112 JSLock::DropAllLocks dropAllLocks ;113 JSLock::DropAllLocks dropAllLocks(exec); 113 114 if (hasProperty(ctx, thisRef, propertyNameRef)) { 114 115 slot.setCustom(this, callbackGetter); … … 116 117 } 117 118 } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) { 118 JSLock::DropAllLocks dropAllLocks ;119 JSLock::DropAllLocks dropAllLocks(exec); 119 120 if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) { 120 121 // cache the value so we don't have to compute it again … … 160 161 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 161 162 if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) { 162 JSLock::DropAllLocks dropAllLocks ;163 JSLock::DropAllLocks dropAllLocks(exec); 163 164 if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) 164 165 return; … … 170 171 return; 171 172 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) { 172 JSLock::DropAllLocks dropAllLocks ;173 JSLock::DropAllLocks dropAllLocks(exec); 173 174 if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) 174 175 return; … … 206 207 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 207 208 if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) { 208 JSLock::DropAllLocks dropAllLocks ;209 JSLock::DropAllLocks dropAllLocks(exec); 209 210 if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 210 211 return true; … … 261 262 for (int i = 0; i < argumentCount; i++) 262 263 arguments[i] = toRef(args[i]); 263 JSLock::DropAllLocks dropAllLocks ;264 JSLock::DropAllLocks dropAllLocks(exec); 264 265 return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 265 266 } … … 288 289 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) 289 290 if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) { 290 JSLock::DropAllLocks dropAllLocks ;291 JSLock::DropAllLocks dropAllLocks(exec); 291 292 return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot())); 292 293 } … … 321 322 for (int i = 0; i < argumentCount; i++) 322 323 arguments[i] = toRef(args[i]); 323 JSLock::DropAllLocks dropAllLocks ;324 JSLock::DropAllLocks dropAllLocks(exec); 324 325 return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 325 326 } … … 338 339 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 339 340 if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) { 340 JSLock::DropAllLocks dropAllLocks ;341 JSLock::DropAllLocks dropAllLocks(exec); 341 342 getPropertyNames(execRef, thisRef, toRef(&propertyNames)); 342 343 } … … 381 382 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) 382 383 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) { 383 JSLock::DropAllLocks dropAllLocks ;384 JSLock::DropAllLocks dropAllLocks(exec); 384 385 if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot()))) 385 386 return toJS(value)->getNumber(); … … 399 400 JSValueRef value; 400 401 { 401 JSLock::DropAllLocks dropAllLocks ;402 JSLock::DropAllLocks dropAllLocks(exec); 402 403 value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot())); 403 404 } … … 452 453 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) 453 454 if (JSObjectGetPropertyCallback getProperty = entry->getProperty) { 454 JSLock::DropAllLocks dropAllLocks ;455 JSLock::DropAllLocks dropAllLocks(exec); 455 456 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 456 457 return toJS(value); … … 497 498 for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) 498 499 if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) { 499 JSLock::DropAllLocks dropAllLocks ;500 JSLock::DropAllLocks dropAllLocks(exec); 500 501 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 501 502 return toJS(value); -
trunk/JavaScriptCore/API/JSContextRef.cpp
r34659 r34947 42 42 initializeThreading(); 43 43 44 JSLock lock ;44 JSLock lock(true); 45 45 46 46 if (!globalObjectClass) { … … 60 60 JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx) 61 61 { 62 JSLock lock;63 62 ExecState* exec = toJS(ctx); 63 JSLock lock(exec); 64 64 gcProtect(exec->dynamicGlobalObject()); 65 65 return ctx; … … 68 68 void JSGlobalContextRelease(JSGlobalContextRef ctx) 69 69 { 70 JSLock lock;71 70 ExecState* exec = toJS(ctx); 71 JSLock lock(exec); 72 72 gcUnprotect(exec->dynamicGlobalObject()); 73 73 } -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r34854 r34947 48 48 JSClassRef JSClassCreate(const JSClassDefinition* definition) 49 49 { 50 JSLock lock;51 50 RefPtr<OpaqueJSClass> jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype) 52 51 ? OpaqueJSClass::createNoAutomaticPrototype(definition) … … 58 57 JSClassRef JSClassRetain(JSClassRef jsClass) 59 58 { 60 JSLock lock;61 59 jsClass->ref(); 62 60 return jsClass; … … 65 63 void JSClassRelease(JSClassRef jsClass) 66 64 { 67 JSLock lock;68 65 jsClass->deref(); 69 66 } … … 71 68 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data) 72 69 { 73 JSLock lock;74 ExecState* exec = toJS(ctx);70 ExecState* exec = toJS(ctx); 71 JSLock lock(exec); 75 72 76 73 if (!jsClass) … … 86 83 JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction) 87 84 { 88 JSLock lock;89 ExecState* exec = toJS(ctx);85 ExecState* exec = toJS(ctx); 86 JSLock lock(exec); 90 87 Identifier nameID = name ? Identifier(exec, toJS(name)) : Identifier(exec, "anonymous"); 91 88 … … 95 92 JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor) 96 93 { 97 JSLock lock;98 ExecState* exec = toJS(ctx);94 ExecState* exec = toJS(ctx); 95 JSLock lock(exec); 99 96 100 97 JSValue* jsPrototype = jsClass … … 109 106 JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 110 107 { 111 JSLock lock;112 113 ExecState* exec = toJS(ctx); 108 ExecState* exec = toJS(ctx); 109 JSLock lock(exec); 110 114 111 UString::Rep* bodyRep = toJS(body); 115 112 UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; … … 148 145 bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) 149 146 { 150 JSLock lock;151 ExecState* exec = toJS(ctx);147 ExecState* exec = toJS(ctx); 148 JSLock lock(exec); 152 149 JSObject* jsObject = toJS(object); 153 150 UString::Rep* nameRep = toJS(propertyName); … … 158 155 JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 159 156 { 160 JSLock lock;161 ExecState* exec = toJS(ctx);157 ExecState* exec = toJS(ctx); 158 JSLock lock(exec); 162 159 JSObject* jsObject = toJS(object); 163 160 UString::Rep* nameRep = toJS(propertyName); … … 174 171 void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) 175 172 { 176 JSLock lock;177 ExecState* exec = toJS(ctx);173 ExecState* exec = toJS(ctx); 174 JSLock lock(exec); 178 175 JSObject* jsObject = toJS(object); 179 176 Identifier name(exec, toJS(propertyName)); … … 194 191 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception) 195 192 { 196 JSLock lock;197 ExecState* exec = toJS(ctx);193 ExecState* exec = toJS(ctx); 194 JSLock lock(exec); 198 195 JSObject* jsObject = toJS(object); 199 196 … … 210 207 void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception) 211 208 { 212 JSLock lock;213 ExecState* exec = toJS(ctx);209 ExecState* exec = toJS(ctx); 210 JSLock lock(exec); 214 211 JSObject* jsObject = toJS(object); 215 212 JSValue* jsValue = toJS(value); … … 225 222 bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 226 223 { 227 JSLock lock;228 ExecState* exec = toJS(ctx);224 ExecState* exec = toJS(ctx); 225 JSLock lock(exec); 229 226 JSObject* jsObject = toJS(object); 230 227 UString::Rep* nameRep = toJS(propertyName); … … 274 271 JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 275 272 { 276 JSLock lock;277 ExecState* exec = toJS(ctx);273 ExecState* exec = toJS(ctx); 274 JSLock lock(exec); 278 275 JSObject* jsObject = toJS(object); 279 276 JSObject* jsThisObject = toJS(thisObject); … … 310 307 JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 311 308 { 312 JSLock lock;313 ExecState* exec = toJS(ctx);309 ExecState* exec = toJS(ctx); 310 JSLock lock(exec); 314 311 JSObject* jsObject = toJS(object); 315 312 … … 344 341 JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object) 345 342 { 346 JS Lock lock;347 JSObject* jsObject = toJS(object);348 ExecState* exec = toJS(ctx);343 JSObject* jsObject = toJS(object); 344 ExecState* exec = toJS(ctx); 345 JSLock lock(exec); 349 346 350 347 JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(&exec->globalData()); … … 356 353 JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array) 357 354 { 358 JSLock lock;359 355 ++array->refCount; 360 356 return array; … … 363 359 void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array) 364 360 { 365 JSLock lock;366 if (--array->refCount == 0)361 if (--array->refCount == 0) { 362 JSLock lock(array->array.globalData()->isSharedInstance); 367 363 delete array; 364 } 368 365 } 369 366 … … 380 377 void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName) 381 378 { 382 JSLock lock;383 379 PropertyNameArray* propertyNames = toJS(array); 384 380 UString::Rep* rep = toJS(propertyName); 381 382 JSLock lock(propertyNames->globalData()->isSharedInstance); 385 383 propertyNames->add(rep); 386 384 } -
trunk/JavaScriptCore/API/JSStringRef.cpp
r34581 r34947 44 44 JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars) 45 45 { 46 JSLock lock;47 46 return toRef(UString(chars, static_cast<int>(numChars)).rep()->ref()); 48 47 } … … 50 49 JSStringRef JSStringCreateWithUTF8CString(const char* string) 51 50 { 52 JSLock lock;53 54 51 RefPtr<UString::Rep> result = UString::Rep::createFromUTF8(string); 55 52 if (result.get() == &UString::Rep::null) … … 61 58 JSStringRef JSStringRetain(JSStringRef string) 62 59 { 63 JSLock lock;64 60 UString::Rep* rep = toJS(string); 65 61 return toRef(rep->ref()); … … 68 64 void JSStringRelease(JSStringRef string) 69 65 { 70 JSLock lock;71 66 UString::Rep* rep = toJS(string); 72 rep->deref(); 67 bool needsLocking = rep->identifierTable; 68 if (needsLocking) { 69 // It is wasteful to take the lock for per-thread contexts, but we don't have a good way 70 // to determine what the context is. 71 JSLock lock(true); 72 rep->deref(); 73 } else 74 rep->deref(); 73 75 } 74 76 … … 95 97 size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize) 96 98 { 97 JSLock lock;98 99 UString::Rep* rep = toJS(string); 99 100 CString cString = UString(rep).UTF8String(); … … 106 107 bool JSStringIsEqual(JSStringRef a, JSStringRef b) 107 108 { 108 JSLock lock;109 110 109 UString::Rep* aRep = toJS(a); 111 110 UString::Rep* bRep = toJS(b); -
trunk/JavaScriptCore/API/JSStringRefCF.cpp
r34581 r34947 38 38 JSStringRef JSStringCreateWithCFString(CFStringRef string) 39 39 { 40 JSLock lock;41 40 CFIndex length = CFStringGetLength(string); 42 41 UString::Rep* rep; -
trunk/JavaScriptCore/API/JSValueRef.cpp
r34659 r34947 119 119 bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception) 120 120 { 121 JSLock lock; 122 ExecState* exec = toJS(ctx); 121 ExecState* exec = toJS(ctx); 122 JSLock lock(exec); 123 123 124 JSValue* jsA = toJS(a); 124 125 JSValue* jsB = toJS(b); … … 133 134 } 134 135 135 bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b) 136 { 137 UNUSED_PARAM(ctx); 138 139 JSLock lock; 136 bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b) 137 { 140 138 JSValue* jsA = toJS(a); 141 139 JSValue* jsB = toJS(b); … … 147 145 bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception) 148 146 { 149 JSLock lock; 150 ExecState* exec = toJS(ctx); 147 ExecState* exec = toJS(ctx); 148 JSLock lock(exec); 149 151 150 JSValue* jsValue = toJS(value); 152 151 JSObject* jsConstructor = toJS(constructor); … … 179 178 JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) 180 179 { 181 JSLock lock; 182 return toRef(jsNumber(toJS(ctx), value)); 180 ExecState* exec = toJS(ctx); 181 JSLock lock(exec); 182 183 return toRef(jsNumber(exec, value)); 183 184 } 184 185 185 186 JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) 186 187 { 187 JSLock lock; 188 ExecState* exec = toJS(ctx); 189 JSLock lock(exec); 190 188 191 UString::Rep* rep = toJS(string); 189 return toRef(jsString( toJS(ctx), UString(rep)));192 return toRef(jsString(exec, UString(rep))); 190 193 } 191 194 … … 199 202 double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception) 200 203 { 201 JSLock lock; 202 JSValue* jsValue = toJS(value); 203 ExecState* exec = toJS(ctx); 204 ExecState* exec = toJS(ctx); 205 JSLock lock(exec); 206 207 JSValue* jsValue = toJS(value); 204 208 205 209 double number = jsValue->toNumber(exec); … … 215 219 JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception) 216 220 { 217 JSLock lock; 218 JSValue* jsValue = toJS(value); 219 ExecState* exec = toJS(ctx); 221 ExecState* exec = toJS(ctx); 222 JSLock lock(exec); 223 224 JSValue* jsValue = toJS(value); 220 225 221 226 JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref()); … … 231 236 JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception) 232 237 { 233 JSLock lock; 234 ExecState* exec = toJS(ctx); 238 ExecState* exec = toJS(ctx); 239 JSLock lock(exec); 240 235 241 JSValue* jsValue = toJS(value); 236 242 … … 245 251 } 246 252 247 void JSValueProtect(JSContextRef, JSValueRef value) 248 { 249 JSLock lock; 253 void JSValueProtect(JSContextRef ctx, JSValueRef value) 254 { 255 ExecState* exec = toJS(ctx); 256 JSLock lock(exec); 257 250 258 JSValue* jsValue = toJS(value); 251 259 gcProtect(jsValue); 252 260 } 253 261 254 void JSValueUnprotect(JSContextRef, JSValueRef value) 255 { 256 JSLock lock; 262 void JSValueUnprotect(JSContextRef ctx, JSValueRef value) 263 { 264 ExecState* exec = toJS(ctx); 265 JSLock lock(exec); 266 257 267 JSValue* jsValue = toJS(value); 258 268 gcUnprotect(jsValue); -
trunk/JavaScriptCore/ChangeLog
r34946 r34947 1 2008-06-30 Alexey Proskuryakov <[email protected]> 2 3 Reviewed by Darin. 4 5 Disable JSLock for per-thread contexts. 6 7 No change on SunSpider. 8 9 * kjs/JSGlobalData.h: 10 * kjs/JSGlobalData.cpp: 11 (KJS::JSGlobalData::JSGlobalData): 12 (KJS::JSGlobalData::sharedInstance): 13 Added isSharedInstance as a better way to tell whether the instance is shared (legacy). 14 15 * kjs/JSLock.cpp: 16 (KJS::createJSLockCount): 17 (KJS::JSLock::lockCount): 18 (KJS::setLockCount): 19 (KJS::JSLock::JSLock): 20 (KJS::JSLock::lock): 21 (KJS::JSLock::unlock): 22 (KJS::JSLock::currentThreadIsHoldingLock): 23 (KJS::JSLock::DropAllLocks::DropAllLocks): 24 (KJS::JSLock::DropAllLocks::~DropAllLocks): 25 * kjs/JSLock.h: 26 (KJS::JSLock::JSLock): 27 (KJS::JSLock::~JSLock): 28 Made JSLock and JSLock::DropAllLocks constructors take a parameter to decide whether to 29 actually lock a mutex, or only to increment recursion count. We cannot turn it into no-op 30 if we want to keep existing assertions working. 31 Made recursion count per-thread, now that locks may not lock. 32 33 * API/JSBase.cpp: 34 (JSEvaluateScript): Take JSLock after casting JSContextRef to ExecState* (which doesn't need 35 locking in any case), so that a decision whether to actually lock can be made. 36 (JSCheckScriptSyntax): Ditto. 37 (JSGarbageCollect): Only lock while collecting the shared heap, not the per-thread one. 38 39 * API/JSObjectRef.cpp: 40 (JSClassCreate): Don't lock, as there is no reason to. 41 (JSClassRetain): Ditto. 42 (JSClassRelease): Ditto. 43 (JSPropertyNameArrayRetain): Ditto. 44 (JSPropertyNameArrayRelease): Only lock while deleting the array, as that may touch 45 identifier table. 46 (JSPropertyNameAccumulatorAddName): Adding a string also involves an identifier table 47 lookup, and possibly modification. 48 49 * API/JSStringRef.cpp: 50 (JSStringCreateWithCharacters): 51 (JSStringCreateWithUTF8CString): 52 (JSStringRetain): 53 (JSStringRelease): 54 (JSStringGetUTF8CString): 55 (JSStringIsEqual): 56 * API/JSStringRefCF.cpp: 57 (JSStringCreateWithCFString): 58 JSStringRef operations other than releasing do not need locking. 59 60 * VM/Machine.cpp: Don't include unused JSLock.h. 61 62 * kjs/CollectorHeapIntrospector.cpp: (KJS::CollectorHeapIntrospector::statistics): 63 Don't take the lock for real, as heap introspection pauses the process anyway. It seems that 64 the existing code could cause deadlocks. 65 66 * kjs/Shell.cpp: 67 (functionGC): 68 (main): 69 (jscmain): 70 The test tool uses a per-thread context, so no real locking is required. 71 72 * kjs/collector.h: 73 (KJS::Heap::setGCProtectNeedsLocking): Optionally protect m_protectedValues access with a 74 per-heap mutex. This is only needed for WebCore Database code, which violates the "no data 75 migration between threads" by using ProtectedPtr on a background thread. 76 (KJS::Heap::isShared): Keep a shared flag here, as well. 77 78 * kjs/protect.h: 79 (KJS::::ProtectedPtr): 80 (KJS::::~ProtectedPtr): 81 (KJS::::operator): 82 (KJS::operator==): 83 (KJS::operator!=): 84 ProtectedPtr is ony used from WebCore, so it doesn't need to take JSLock. An assertion in 85 Heap::protect/unprotect guards agains possible future unlocked uses of ProtectedPtr in JSC. 86 87 * kjs/collector.cpp: 88 (KJS::Heap::Heap): Initialize m_isShared. 89 (KJS::Heap::~Heap): No need to lock for real during destruction, but must keep assertions 90 in sweep() working. 91 (KJS::destroyRegisteredThread): Registered thread list is only accessed for shared heap, 92 so locking is always needed here. 93 (KJS::Heap::registerThread): Ditto. 94 (KJS::Heap::markStackObjectsConservatively): Use m_isShared instead of comparing to a shared 95 instance for a small speedup. 96 (KJS::Heap::setGCProtectNeedsLocking): Create m_protectedValuesMutex. There is currently no 97 way to undo this - and ideally, Database code will be fixed to lo longer require this quirk. 98 (KJS::Heap::protect): Take m_protectedValuesMutex (if it exists) while accessing 99 m_protectedValues. 100 (KJS::Heap::unprotect): Ditto. 101 (KJS::Heap::markProtectedObjects): Ditto. 102 (KJS::Heap::protectedGlobalObjectCount): Ditto. 103 (KJS::Heap::protectedObjectCount): Ditto. 104 (KJS::Heap::protectedObjectTypeCounts): Ditto. 105 106 * kjs/ustring.cpp: 107 * kjs/ustring.h: 108 Don't include JSLock.h, which is no longer used here. As a result, an explicit include had 109 to be added to many files in JavaScriptGlue, WebCore and WebKit. 110 111 * kjs/JSGlobalObject.cpp: 112 (KJS::JSGlobalObject::init): 113 * API/JSCallbackConstructor.cpp: 114 (KJS::constructJSCallback): 115 * API/JSCallbackFunction.cpp: 116 (KJS::JSCallbackFunction::call): 117 * API/JSCallbackObjectFunctions.h: 118 (KJS::::init): 119 (KJS::::getOwnPropertySlot): 120 (KJS::::put): 121 (KJS::::deleteProperty): 122 (KJS::::construct): 123 (KJS::::hasInstance): 124 (KJS::::call): 125 (KJS::::getPropertyNames): 126 (KJS::::toNumber): 127 (KJS::::toString): 128 (KJS::::staticValueGetter): 129 (KJS::::callbackGetter): 130 * API/JSContextRef.cpp: 131 (JSGlobalContextCreate): 132 (JSGlobalContextRetain): 133 (JSGlobalContextRelease): 134 * API/JSValueRef.cpp: 135 (JSValueIsEqual): 136 (JSValueIsStrictEqual): 137 (JSValueIsInstanceOfConstructor): 138 (JSValueMakeNumber): 139 (JSValueMakeString): 140 (JSValueToNumber): 141 (JSValueToStringCopy): 142 (JSValueToObject): 143 (JSValueProtect): 144 (JSValueUnprotect): 145 * JavaScriptCore.exp: 146 * kjs/PropertyNameArray.h: 147 (KJS::PropertyNameArray::globalData): 148 * kjs/interpreter.cpp: 149 (KJS::Interpreter::checkSyntax): 150 (KJS::Interpreter::evaluate): 151 Pass a parameter to JSLock/JSLock::DropAllLocks to decide whether the lock needs to be taken. 152 1 153 2008-07-01 Alexey Proskuryakov <[email protected]> 2 154 … … 306 458 (WTF::): Updated HashTraits for HashTable change. 307 459 308 2008-0 6-30Alexey Proskuryakov <[email protected]>460 2008-07-01 Alexey Proskuryakov <[email protected]> 309 461 310 462 Reviewed by Cameron Zwarich. -
trunk/JavaScriptCore/JavaScriptCore.exp
r34933 r34947 148 148 __ZN3KJS4Heap17globalObjectCountEv 149 149 __ZN3KJS4Heap20protectedObjectCountEv 150 __ZN3KJS4Heap24setGCProtectNeedsLockingEv 150 151 __ZN3KJS4Heap25protectedObjectTypeCountsEv 151 152 __ZN3KJS4Heap26protectedGlobalObjectCountEv … … 170 171 __ZN3KJS6JSCell9getObjectEv 171 172 __ZN3KJS6JSCellnwEmPNS_9ExecStateE 172 __ZN3KJS6JSLock12DropAllLocksC1Ev 173 __ZN3KJS6JSLock12DropAllLocksC1Eb 174 __ZN3KJS6JSLock12DropAllLocksC1EPNS_9ExecStateE 173 175 __ZN3KJS6JSLock12DropAllLocksD1Ev 174 176 __ZN3KJS6JSLock14registerThreadEv 175 __ZN3KJS6JSLock4lockE v176 __ZN3KJS6JSLock6unlockE v177 __ZN3KJS6JSLock4lockEb 178 __ZN3KJS6JSLock6unlockEb 177 179 __ZN3KJS6JSLock9lockCountEv 180 __ZN3KJS6JSLockC1EPNS_9ExecStateE 178 181 __ZN3KJS6Parser5parseEPNS_9ExecStateERKNS_7UStringEiN3WTF10PassRefPtrINS_14SourceProviderEEEPiSA_PS3_ 179 182 __ZN3KJS6strtodEPKcPPc -
trunk/JavaScriptCore/VM/Machine.cpp
r34945 r34947 38 38 #include "JSArray.h" 39 39 #include "JSFunction.h" 40 #include "JSLock.h"41 40 #include "JSPropertyNameIterator.h" 42 41 #include "JSString.h" -
trunk/JavaScriptCore/kjs/CollectorHeapIntrospector.cpp
r34824 r34947 96 96 void CollectorHeapIntrospector::statistics(malloc_zone_t* zone, malloc_statistics_t* stats) 97 97 { 98 JSLock lock ;98 JSLock lock(false); 99 99 CollectorHeapIntrospector* introspector = reinterpret_cast<CollectorHeapIntrospector*>(zone); 100 100 CollectorHeap* primaryHeap = introspector->m_primaryHeap; -
trunk/JavaScriptCore/kjs/JSGlobalData.cpp
r34907 r34947 57 57 58 58 59 JSGlobalData::JSGlobalData( )59 JSGlobalData::JSGlobalData(bool isShared) 60 60 : machine(new Machine) 61 , heap(new Heap )61 , heap(new Heap(isShared)) 62 62 #if USE(MULTIPLE_THREADS) 63 63 , arrayTable(new HashTable(KJS::arrayTable)) … … 84 84 , parser(new Parser) 85 85 , head(0) 86 , isSharedInstance(isShared) 86 87 { 87 88 } … … 133 134 { 134 135 #if USE(MULTIPLE_THREADS) 135 AtomicallyInitializedStatic(JSGlobalData, sharedInstance); 136 #else 137 static JSGlobalData sharedInstance; 136 MutexLocker locker(*atomicallyInitializedStaticMutex); 138 137 #endif 139 return sharedInstance; 138 static JSGlobalData* sharedInstance; 139 if (!sharedInstance) 140 sharedInstance = new JSGlobalData(true); 141 return *sharedInstance; 140 142 } 141 143 -
trunk/JavaScriptCore/kjs/JSGlobalData.h
r34838 r34947 82 82 JSGlobalObject* head; 83 83 84 bool isSharedInstance; 85 84 86 private: 85 87 friend class WTF::ThreadSpecific<JSGlobalData>; 86 88 87 JSGlobalData( );89 JSGlobalData(bool isShared = false); 88 90 ~JSGlobalData(); 89 91 }; -
trunk/JavaScriptCore/kjs/JSGlobalObject.cpp
r34946 r34947 102 102 ASSERT(JSLock::currentThreadIsHoldingLock()); 103 103 104 d()->globalData = (Heap::heap(this) == JSGlobalData::sharedInstance().heap) ? &JSGlobalData::sharedInstance() : &JSGlobalData::threadInstance();104 d()->globalData = Heap::heap(this)->isShared() ? &JSGlobalData::sharedInstance() : &JSGlobalData::threadInstance(); 105 105 106 106 if (JSGlobalObject*& headObject = head()) { -
trunk/JavaScriptCore/kjs/JSLock.cpp
r34659 r34947 25 25 26 26 #include "collector.h" 27 #include "ExecState.h" 28 27 29 #if USE(MULTIPLE_THREADS) 28 30 #include <pthread.h> … … 36 38 static pthread_mutex_t JSMutex = PTHREAD_MUTEX_INITIALIZER; 37 39 38 // Thread-specific key that tells whether a thread holds the JSMutex. 39 pthread_key_t didLockJSMutex; 40 // Thread-specific key that tells whether a thread holds the JSMutex, and how many times it was taken recursively. 41 pthread_key_t JSLockCount; 42 43 static void createJSLockCount() 44 { 45 pthread_key_create(&JSLockCount, 0); 46 } 47 48 pthread_once_t createJSLockCountOnce = PTHREAD_ONCE_INIT; 40 49 41 50 // Lock nesting count. 42 static int JSLockCount; 51 int JSLock::lockCount() 52 { 53 pthread_once(&createJSLockCountOnce, createJSLockCount); 43 54 44 static void createDidLockJSMutex() 55 return reinterpret_cast<int>(pthread_getspecific(JSLockCount)); 56 } 57 58 static void setLockCount(int count) 45 59 { 46 pthread_ key_create(&didLockJSMutex, 0);60 pthread_setspecific(JSLockCount, reinterpret_cast<void*>(count)); 47 61 } 48 pthread_once_t createDidLockJSMutexOnce = PTHREAD_ONCE_INIT;49 62 50 void JSLock::lock() 63 JSLock::JSLock(ExecState* exec) 64 : m_lockingForReal(exec->globalData().isSharedInstance) 51 65 { 52 pthread_once(&createDidLockJSMutexOnce, createDidLockJSMutex); 66 lock(m_lockingForReal); 67 if (m_lockingForReal) 68 registerThread(); 69 } 53 70 54 if (!pthread_getspecific(didLockJSMutex)) { 71 void JSLock::lock(bool lockForReal) 72 { 73 #ifdef NDEBUG 74 // For per-thread contexts, locking is a debug-only feature. 75 if (!lockForReal) 76 return; 77 #endif 78 79 pthread_once(&createJSLockCountOnce, createJSLockCount); 80 81 int currentLockCount = lockCount(); 82 if (!currentLockCount && lockForReal) { 55 83 int result; 56 84 result = pthread_mutex_lock(&JSMutex); 57 85 ASSERT(!result); 58 pthread_setspecific(didLockJSMutex, &didLockJSMutex);59 86 } 60 ++JSLockCount;87 setLockCount(currentLockCount + 1); 61 88 } 62 89 63 void JSLock::unlock( )90 void JSLock::unlock(bool lockForReal) 64 91 { 65 ASSERT(JSLockCount); 66 ASSERT(!!pthread_getspecific(didLockJSMutex)); 92 ASSERT(lockCount()); 67 93 68 --JSLockCount; 69 if (!JSLockCount) { 70 pthread_setspecific(didLockJSMutex, 0); 94 #ifdef NDEBUG 95 // For per-thread contexts, locking is a debug-only feature. 96 if (!lockForReal) 97 return; 98 #endif 99 100 int newLockCount = lockCount() - 1; 101 setLockCount(newLockCount); 102 if (!newLockCount && lockForReal) { 71 103 int result; 72 104 result = pthread_mutex_unlock(&JSMutex); … … 75 107 } 76 108 109 void JSLock::lock(ExecState* exec) 110 { 111 lock(exec->globalData().isSharedInstance); 112 } 113 114 void JSLock::unlock(ExecState* exec) 115 { 116 unlock(exec->globalData().isSharedInstance); 117 } 118 77 119 bool JSLock::currentThreadIsHoldingLock() 78 120 { 79 pthread_once(&create DidLockJSMutexOnce, createDidLockJSMutex);80 return !!pthread_getspecific( didLockJSMutex);121 pthread_once(&createJSLockCountOnce, createJSLockCount); 122 return !!pthread_getspecific(JSLockCount); 81 123 } 82 124 … … 86 128 } 87 129 88 JSLock::DropAllLocks::DropAllLocks( )89 : m_lock Count(0)130 JSLock::DropAllLocks::DropAllLocks(ExecState* exec) 131 : m_lockingForReal(exec->globalData().isSharedInstance) 90 132 { 91 pthread_once(&create DidLockJSMutexOnce, createDidLockJSMutex);133 pthread_once(&createJSLockCountOnce, createJSLockCount); 92 134 93 m_lockCount = !!pthread_getspecific(didLockJSMutex) ? JSLock::lockCount() : 0;135 m_lockCount = JSLock::lockCount(); 94 136 for (int i = 0; i < m_lockCount; i++) 95 JSLock::unlock(); 137 JSLock::unlock(m_lockingForReal); 138 } 139 140 JSLock::DropAllLocks::DropAllLocks(bool lockingForReal) 141 : m_lockingForReal(lockingForReal) 142 { 143 pthread_once(&createJSLockCountOnce, createJSLockCount); 144 145 // It is necessary to drop even "unreal" locks, because having a non-zero lock count 146 // will prevent a real lock from being taken. 147 148 m_lockCount = JSLock::lockCount(); 149 for (int i = 0; i < m_lockCount; i++) 150 JSLock::unlock(m_lockingForReal); 96 151 } 97 152 … … 99 154 { 100 155 for (int i = 0; i < m_lockCount; i++) 101 JSLock::lock(); 102 m_lockCount = 0; 156 JSLock::lock(m_lockingForReal); 103 157 } 104 158 … … 107 161 // If threading support is off, set the lock count to a constant value of 1 so assertions 108 162 // that the lock is held don't fail 109 const int JSLockCount = 1; 163 int JSLock::lockCount() 164 { 165 return 1; 166 } 110 167 111 168 bool JSLock::currentThreadIsHoldingLock() … … 136 193 #endif // USE(MULTIPLE_THREADS) 137 194 138 int JSLock::lockCount()139 {140 return JSLockCount;141 195 } 142 143 } -
trunk/JavaScriptCore/kjs/JSLock.h
r33038 r34947 47 47 // thread acquired it to begin with. 48 48 49 // For per-thread contexts, JSLock doesn't do any locking, but we 50 // still need to perform all the counting in order to keep debug 51 // assertions working, so that clients that use a shared context don't break. 52 53 class ExecState; 54 49 55 class JSLock : Noncopyable { 50 56 public: 51 JSLock() 57 JSLock(ExecState* exec); 58 59 JSLock(bool lockingForReal) 60 : m_lockingForReal(lockingForReal) 52 61 { 53 lock(); 54 registerThread(); 62 #ifdef NDEBUG 63 // For per-thread contexts, locking is a debug-only feature. 64 if (!lockingForReal) 65 return; 66 #endif 67 lock(lockingForReal); 68 if (lockingForReal) 69 registerThread(); 55 70 } 56 71 57 ~JSLock() 72 ~JSLock() 58 73 { 59 unlock(); 74 #ifdef NDEBUG 75 // For per-thread contexts, locking is a debug-only feature. 76 if (!m_lockingForReal) 77 return; 78 #endif 79 unlock(m_lockingForReal); 60 80 } 61 81 62 static void lock(); 63 static void unlock(); 82 static void lock(bool); 83 static void unlock(bool); 84 static void lock(ExecState*); 85 static void unlock(ExecState*); 86 64 87 static int lockCount(); 65 88 static bool currentThreadIsHoldingLock(); … … 67 90 static void registerThread(); 68 91 92 bool m_lockingForReal; 93 69 94 class DropAllLocks : Noncopyable { 70 95 public: 71 DropAllLocks(); 96 DropAllLocks(ExecState* exec); 97 DropAllLocks(bool); 72 98 ~DropAllLocks(); 73 99 74 100 private: 75 101 int m_lockCount; 102 bool m_lockingForReal; 76 103 }; 77 104 }; -
trunk/JavaScriptCore/kjs/PropertyNameArray.h
r34611 r34947 38 38 PropertyNameArray(ExecState* exec) : m_globalData(&exec->globalData()) {} 39 39 40 JSGlobalData* globalData() { return m_globalData; } 41 40 42 void add(const Identifier& identifier) { add(identifier.ustring().rep()); } 41 43 void add(UString::Rep*); -
trunk/JavaScriptCore/kjs/Shell.cpp
r34854 r34947 207 207 JSValue* functionGC(ExecState* exec, JSObject*, JSValue*, const ArgList&) 208 208 { 209 JSLock lock ;209 JSLock lock(false); 210 210 exec->heap()->collect(); 211 211 return jsUndefined(); … … 302 302 res = jscmain(argc, argv); 303 303 #ifndef NDEBUG 304 JSLock::lock( );304 JSLock::lock(false); 305 305 JSGlobalData::threadInstance().heap->collect(); 306 JSLock::unlock( );306 JSLock::unlock(false); 307 307 #endif 308 308 EXCEPT(res = 3) … … 448 448 int jscmain(int argc, char** argv) 449 449 { 450 initializeThreading();451 452 JSLock lock ;450 KJS::initializeThreading(); 451 452 JSLock lock(false); 453 453 454 454 Options options; -
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 } -
trunk/JavaScriptCore/kjs/collector.h
r34907 r34947 27 27 #include <wtf/HashSet.h> 28 28 #include <wtf/Noncopyable.h> 29 #include <wtf/OwnPtr.h> 30 #include <wtf/Threading.h> 29 31 30 32 namespace KJS { … … 76 78 size_t size(); 77 79 80 void setGCProtectNeedsLocking(); 78 81 void protect(JSValue*); 79 82 void unprotect(JSValue*); … … 98 101 99 102 HashSet<ArgList*>& markListSet() { if (!m_markListSet) m_markListSet = new HashSet<ArgList*>; return *m_markListSet; } 103 104 bool isShared() const { return m_isShared; } 100 105 101 106 private: … … 106 111 static size_t cellOffset(const JSCell*); 107 112 108 friend class Machine;109 113 friend class JSGlobalData; 110 Heap( );114 Heap(bool isShared); 111 115 ~Heap(); 112 116 … … 122 126 CollectorHeap primaryHeap; 123 127 CollectorHeap numberHeap; 124 ProtectCountSet protectedValues; 128 129 OwnPtr<Mutex> m_protectedValuesMutex; // Only non-null if the client explicitly requested it via setGCPrtotectNeedsLocking(). 130 ProtectCountSet m_protectedValues; 131 125 132 HashSet<ArgList*>* m_markListSet; 133 134 bool m_isShared; 126 135 }; 127 136 -
trunk/JavaScriptCore/kjs/interpreter.cpp
r34842 r34947 46 46 Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source) 47 47 { 48 JSLock lock ;48 JSLock lock(exec); 49 49 50 50 int errLine; … … 64 64 Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue) 65 65 { 66 JSLock lock ;66 JSLock lock(exec); 67 67 68 68 // parse the source code -
trunk/JavaScriptCore/kjs/protect.h
r34659 r34947 27 27 #include "JSValue.h" 28 28 #include "collector.h" 29 #include "JSLock.h"30 29 31 30 namespace KJS { … … 63 62 ProtectedPtr() : m_ptr(NULL) { } 64 63 ProtectedPtr(T *ptr); 65 ProtectedPtr(const ProtectedPtr 64 ProtectedPtr(const ProtectedPtr&); 66 65 ~ProtectedPtr(); 67 66 68 template <class U> ProtectedPtr(const ProtectedPtr<U> 67 template <class U> ProtectedPtr(const ProtectedPtr<U>&); 69 68 70 69 T *get() const { return m_ptr; } … … 74 73 bool operator!() const { return m_ptr == NULL; } 75 74 76 ProtectedPtr &operator=(const ProtectedPtr&);77 ProtectedPtr &operator=(T*);75 ProtectedPtr& operator=(const ProtectedPtr&); 76 ProtectedPtr& operator=(T*); 78 77 79 78 private: … … 84 83 : m_ptr(ptr) 85 84 { 86 if (ptr) { 87 JSLock lock; 85 if (ptr) 88 86 gcProtect(ptr); 89 }90 87 } 91 88 92 template <class T> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr &o)89 template <class T> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr& o) 93 90 : m_ptr(o.get()) 94 91 { 95 if (T *ptr = m_ptr) { 96 JSLock lock; 92 if (T *ptr = m_ptr) 97 93 gcProtect(ptr); 98 }99 94 } 100 95 101 96 template <class T> ProtectedPtr<T>::~ProtectedPtr() 102 97 { 103 if (T *ptr = m_ptr) { 104 JSLock lock; 98 if (T *ptr = m_ptr) 105 99 gcUnprotect(ptr); 106 }107 100 } 108 101 109 template <class T> template <class U> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U> &o)102 template <class T> template <class U> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U>& o) 110 103 : m_ptr(o.get()) 111 104 { 112 if (T *ptr = m_ptr) { 113 JSLock lock; 105 if (T *ptr = m_ptr) 114 106 gcProtect(ptr); 115 }116 107 } 117 108 118 template <class T> ProtectedPtr<T> &ProtectedPtr<T>::operator=(const ProtectedPtr<T> &o)109 template <class T> ProtectedPtr<T>& ProtectedPtr<T>::operator=(const ProtectedPtr<T>& o) 119 110 { 120 JSLock lock;121 111 T *optr = o.m_ptr; 122 112 gcProtectNullTolerant(optr); … … 126 116 } 127 117 128 template <class T> inline ProtectedPtr<T> &ProtectedPtr<T>::operator=(T *optr)118 template <class T> inline ProtectedPtr<T>& ProtectedPtr<T>::operator=(T* optr) 129 119 { 130 JSLock lock;131 120 gcProtectNullTolerant(optr); 132 121 gcUnprotectNullTolerant(m_ptr); … … 135 124 } 136 125 137 template <class T> inline bool operator==(const ProtectedPtr<T> &a, const ProtectedPtr<T> &b) { return a.get() == b.get(); }138 template <class T> inline bool operator==(const ProtectedPtr<T> &a, const T *b) { return a.get() == b; }139 template <class T> inline bool operator==(const T *a, const ProtectedPtr<T> &b) { return a == b.get(); }126 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() == b.get(); } 127 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const T* b) { return a.get() == b; } 128 template <class T> inline bool operator==(const T* a, const ProtectedPtr<T>& b) { return a == b.get(); } 140 129 141 template <class T> inline bool operator!=(const ProtectedPtr<T> &a, const ProtectedPtr<T> &b) { return a.get() != b.get(); }142 template <class T> inline bool operator!=(const ProtectedPtr<T> &a, const T *b) { return a.get() != b; }143 template <class T> inline bool operator!=(const T *a, const ProtectedPtr<T> &b) { return a != b.get(); }130 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() != b.get(); } 131 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const T* b) { return a.get() != b; } 132 template <class T> inline bool operator!=(const T* a, const ProtectedPtr<T>& b) { return a != b.get(); } 144 133 145 134 } // namespace -
trunk/JavaScriptCore/kjs/ustring.cpp
r34821 r34947 25 25 #include "ustring.h" 26 26 27 #include "JSLock.h"28 27 #include "collector.h" 29 28 #include "dtoa.h" -
trunk/JavaScriptCore/kjs/ustring.h
r34821 r34947 24 24 #define _KJS_USTRING_H_ 25 25 26 #include "JSLock.h"27 26 #include "collector.h" 28 27 #include <stdint.h>
Note:
See TracChangeset
for help on using the changeset viewer.