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/JSCallbackObjectFunctions.h

    r34754 r34947  
    3030#include "JSClassRef.h"
    3131#include "JSGlobalObject.h"
     32#include "JSLock.h"
    3233#include "JSObjectRef.h"
    3334#include "JSString.h"
     
    7273    // initialize from base to derived
    7374    for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
    74         JSLock::DropAllLocks dropAllLocks;
     75        JSLock::DropAllLocks dropAllLocks(exec);
    7576        JSObjectInitializeCallback initialize = initRoutines[i];
    7677        initialize(toRef(exec), toRef(this));
     
    110111        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    111112        if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
    112             JSLock::DropAllLocks dropAllLocks;
     113            JSLock::DropAllLocks dropAllLocks(exec);
    113114            if (hasProperty(ctx, thisRef, propertyNameRef)) {
    114115                slot.setCustom(this, callbackGetter);
     
    116117            }
    117118        } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
    118             JSLock::DropAllLocks dropAllLocks;
     119            JSLock::DropAllLocks dropAllLocks(exec);
    119120            if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    120121                // cache the value so we don't have to compute it again
     
    160161    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    161162        if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
    162             JSLock::DropAllLocks dropAllLocks;
     163            JSLock::DropAllLocks dropAllLocks(exec);
    163164            if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    164165                return;
     
    170171                    return;
    171172                if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
    172                     JSLock::DropAllLocks dropAllLocks;
     173                    JSLock::DropAllLocks dropAllLocks(exec);
    173174                    if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    174175                        return;
     
    206207    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    207208        if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
    208             JSLock::DropAllLocks dropAllLocks;
     209            JSLock::DropAllLocks dropAllLocks(exec);
    209210            if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    210211                return true;
     
    261262            for (int i = 0; i < argumentCount; i++)
    262263                arguments[i] = toRef(args[i]);
    263             JSLock::DropAllLocks dropAllLocks;
     264            JSLock::DropAllLocks dropAllLocks(exec);
    264265            return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
    265266        }
     
    288289    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
    289290        if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
    290             JSLock::DropAllLocks dropAllLocks;
     291            JSLock::DropAllLocks dropAllLocks(exec);
    291292            return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
    292293        }
     
    321322            for (int i = 0; i < argumentCount; i++)
    322323                arguments[i] = toRef(args[i]);
    323             JSLock::DropAllLocks dropAllLocks;
     324            JSLock::DropAllLocks dropAllLocks(exec);
    324325            return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
    325326        }
     
    338339    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
    339340        if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
    340             JSLock::DropAllLocks dropAllLocks;
     341            JSLock::DropAllLocks dropAllLocks(exec);
    341342            getPropertyNames(execRef, thisRef, toRef(&propertyNames));
    342343        }
     
    381382    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
    382383        if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
    383             JSLock::DropAllLocks dropAllLocks;
     384            JSLock::DropAllLocks dropAllLocks(exec);
    384385            if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
    385386                return toJS(value)->getNumber();
     
    399400            JSValueRef value;
    400401            {
    401                 JSLock::DropAllLocks dropAllLocks;
     402                JSLock::DropAllLocks dropAllLocks(exec);
    402403                value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()));
    403404            }
     
    452453            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
    453454                if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
    454                     JSLock::DropAllLocks dropAllLocks;
     455                    JSLock::DropAllLocks dropAllLocks(exec);
    455456                    if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    456457                        return toJS(value);
     
    497498    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
    498499        if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
    499             JSLock::DropAllLocks dropAllLocks;
     500            JSLock::DropAllLocks dropAllLocks(exec);
    500501            if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    501502                return toJS(value);
Note: See TracChangeset for help on using the changeset viewer.