Ignore:
Timestamp:
Jul 2, 2008, 12:00:53 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Disable JSLock for per-thread contexts.

No change on SunSpider.

  • kjs/JSGlobalData.h:
  • kjs/JSGlobalData.cpp: (KJS::JSGlobalData::JSGlobalData): (KJS::JSGlobalData::sharedInstance): Added isSharedInstance as a better way to tell whether the instance is shared (legacy).
  • kjs/JSLock.cpp: (KJS::createJSLockCount): (KJS::JSLock::lockCount): (KJS::setLockCount): (KJS::JSLock::JSLock): (KJS::JSLock::lock): (KJS::JSLock::unlock): (KJS::JSLock::currentThreadIsHoldingLock): (KJS::JSLock::DropAllLocks::DropAllLocks): (KJS::JSLock::DropAllLocks::~DropAllLocks):
  • kjs/JSLock.h: (KJS::JSLock::JSLock): (KJS::JSLock::~JSLock): Made JSLock and JSLock::DropAllLocks constructors take a parameter to decide whether to actually lock a mutex, or only to increment recursion count. We cannot turn it into no-op if we want to keep existing assertions working. Made recursion count per-thread, now that locks may not lock.
  • API/JSBase.cpp: (JSEvaluateScript): Take JSLock after casting JSContextRef to ExecState* (which doesn't need locking in any case), so that a decision whether to actually lock can be made. (JSCheckScriptSyntax): Ditto. (JSGarbageCollect): Only lock while collecting the shared heap, not the per-thread one.
  • API/JSObjectRef.cpp: (JSClassCreate): Don't lock, as there is no reason to. (JSClassRetain): Ditto. (JSClassRelease): Ditto. (JSPropertyNameArrayRetain): Ditto. (JSPropertyNameArrayRelease): Only lock while deleting the array, as that may touch identifier table. (JSPropertyNameAccumulatorAddName): Adding a string also involves an identifier table lookup, and possibly modification.
  • API/JSStringRef.cpp: (JSStringCreateWithCharacters): (JSStringCreateWithUTF8CString): (JSStringRetain): (JSStringRelease): (JSStringGetUTF8CString): (JSStringIsEqual):
  • API/JSStringRefCF.cpp: (JSStringCreateWithCFString): JSStringRef operations other than releasing do not need locking.
  • VM/Machine.cpp: Don't include unused JSLock.h.
  • kjs/CollectorHeapIntrospector.cpp: (KJS::CollectorHeapIntrospector::statistics): Don't take the lock for real, as heap introspection pauses the process anyway. It seems that the existing code could cause deadlocks.
  • kjs/Shell.cpp: (functionGC): (main): (jscmain): The test tool uses a per-thread context, so no real locking is required.
  • kjs/collector.h: (KJS::Heap::setGCProtectNeedsLocking): Optionally protect m_protectedValues access with a per-heap mutex. This is only needed for WebCore Database code, which violates the "no data migration between threads" by using ProtectedPtr on a background thread. (KJS::Heap::isShared): Keep a shared flag here, as well.
  • kjs/protect.h: (KJS::::ProtectedPtr): (KJS::::~ProtectedPtr): (KJS::::operator): (KJS::operator==): (KJS::operator!=): ProtectedPtr is ony used from WebCore, so it doesn't need to take JSLock. An assertion in Heap::protect/unprotect guards agains possible future unlocked uses of ProtectedPtr in JSC.
  • kjs/collector.cpp: (KJS::Heap::Heap): Initialize m_isShared. (KJS::Heap::~Heap): No need to lock for real during destruction, but must keep assertions in sweep() working. (KJS::destroyRegisteredThread): Registered thread list is only accessed for shared heap, so locking is always needed here. (KJS::Heap::registerThread): Ditto. (KJS::Heap::markStackObjectsConservatively): Use m_isShared instead of comparing to a shared instance for a small speedup. (KJS::Heap::setGCProtectNeedsLocking): Create m_protectedValuesMutex. There is currently no way to undo this - and ideally, Database code will be fixed to lo longer require this quirk. (KJS::Heap::protect): Take m_protectedValuesMutex (if it exists) while accessing m_protectedValues. (KJS::Heap::unprotect): Ditto. (KJS::Heap::markProtectedObjects): Ditto. (KJS::Heap::protectedGlobalObjectCount): Ditto. (KJS::Heap::protectedObjectCount): Ditto. (KJS::Heap::protectedObjectTypeCounts): Ditto.
  • kjs/ustring.cpp:
  • kjs/ustring.h: Don't include JSLock.h, which is no longer used here. As a result, an explicit include had to be added to many files in JavaScriptGlue, WebCore and WebKit.
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::init):
  • API/JSCallbackConstructor.cpp: (KJS::constructJSCallback):
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::call):
  • API/JSCallbackObjectFunctions.h: (KJS::::init): (KJS::::getOwnPropertySlot): (KJS::::put): (KJS::::deleteProperty): (KJS::::construct): (KJS::::hasInstance): (KJS::::call): (KJS::::getPropertyNames): (KJS::::toNumber): (KJS::::toString): (KJS::::staticValueGetter): (KJS::::callbackGetter):
  • API/JSContextRef.cpp: (JSGlobalContextCreate): (JSGlobalContextRetain): (JSGlobalContextRelease):
  • API/JSValueRef.cpp: (JSValueIsEqual): (JSValueIsStrictEqual): (JSValueIsInstanceOfConstructor): (JSValueMakeNumber): (JSValueMakeString): (JSValueToNumber): (JSValueToStringCopy): (JSValueToObject): (JSValueProtect): (JSValueUnprotect):
  • JavaScriptCore.exp:
  • kjs/PropertyNameArray.h: (KJS::PropertyNameArray::globalData):
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate): Pass a parameter to JSLock/JSLock::DropAllLocks to decide whether the lock needs to be taken.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r34659 r34947  
    119119bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception)
    120120{
    121     JSLock lock;
    122     ExecState* exec = toJS(ctx);
     121    ExecState* exec = toJS(ctx);
     122    JSLock lock(exec);
     123
    123124    JSValue* jsA = toJS(a);
    124125    JSValue* jsB = toJS(b);
     
    133134}
    134135
    135 bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
    136 {
    137     UNUSED_PARAM(ctx);
    138 
    139     JSLock lock;
     136bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b)
     137{
    140138    JSValue* jsA = toJS(a);
    141139    JSValue* jsB = toJS(b);
     
    147145bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
    148146{
    149     JSLock lock;
    150     ExecState* exec = toJS(ctx);
     147    ExecState* exec = toJS(ctx);
     148    JSLock lock(exec);
     149
    151150    JSValue* jsValue = toJS(value);
    152151    JSObject* jsConstructor = toJS(constructor);
     
    179178JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
    180179{
    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));
    183184}
    184185
    185186JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
    186187{
    187     JSLock lock;
     188    ExecState* exec = toJS(ctx);
     189    JSLock lock(exec);
     190
    188191    UString::Rep* rep = toJS(string);
    189     return toRef(jsString(toJS(ctx), UString(rep)));
     192    return toRef(jsString(exec, UString(rep)));
    190193}
    191194
     
    199202double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
    200203{
    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);
    204208
    205209    double number = jsValue->toNumber(exec);
     
    215219JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
    216220{
    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);
    220225   
    221226    JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
     
    231236JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
    232237{
    233     JSLock lock;
    234     ExecState* exec = toJS(ctx);
     238    ExecState* exec = toJS(ctx);
     239    JSLock lock(exec);
     240
    235241    JSValue* jsValue = toJS(value);
    236242   
     
    245251}   
    246252
    247 void JSValueProtect(JSContextRef, JSValueRef value)
    248 {
    249     JSLock lock;
     253void JSValueProtect(JSContextRef ctx, JSValueRef value)
     254{
     255    ExecState* exec = toJS(ctx);
     256    JSLock lock(exec);
     257
    250258    JSValue* jsValue = toJS(value);
    251259    gcProtect(jsValue);
    252260}
    253261
    254 void JSValueUnprotect(JSContextRef, JSValueRef value)
    255 {
    256     JSLock lock;
     262void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
     263{
     264    ExecState* exec = toJS(ctx);
     265    JSLock lock(exec);
     266
    257267    JSValue* jsValue = toJS(value);
    258268    gcUnprotect(jsValue);
Note: See TracChangeset for help on using the changeset viewer.