Ignore:
Timestamp:
Oct 7, 2009, 6:46:07 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore: Fixed <rdar://problem/5751979> Database code takes JSLock on secondary
thread, permanently slowing down JavaScript

Patch by Geoffrey Garen <[email protected]> on 2009-10-07
Reviewed by Oliver Hunt.

Removed the optional lock from Heap::protect, Heap::unprotect, and friends,
since WebCore no longer uses it.

(JSC::Heap::protect):
(JSC::Heap::unprotect):
(JSC::Heap::markProtectedObjects):
(JSC::Heap::protectedGlobalObjectCount):
(JSC::Heap::protectedObjectCount):
(JSC::Heap::protectedObjectTypeCounts):

  • runtime/Collector.h:

WebCore: Fixed <rdar://problem/5751979> Database code takes JSLock on secondary
thread, permanently slowing down JavaScript

Patch by Geoffrey Garen <[email protected]> on 2009-10-07
Reviewed by Oliver Hunt.

Changed callback objects to use a standard helper object. The helper
object ASSERTs that it is deleted on the main thread, so no lock is
required when unprotecting its members. It also centralizes some previously
duplicated code.

Callback objects that might be deleted on a secondary thread use
callOnMainThread to delete their helper objects on the main thread.

  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSCallbackData.cpp: Copied from bindings/js/JSCustomSQLTransactionCallback.cpp.

(WebCore::JSCallbackData::deleteData):
(WebCore::JSCallbackData::invokeCallback):

  • bindings/js/JSCallbackData.h: Copied from bindings/js/JSCustomSQLTransactionCallback.cpp.

(WebCore::JSCallbackData::JSCallbackData):
(WebCore::JSCallbackData::~JSCallbackData):
(WebCore::JSCallbackData::callback):

  • bindings/js/JSCustomPositionCallback.cpp:

(WebCore::JSCustomPositionCallback::JSCustomPositionCallback):
(WebCore::JSCustomPositionCallback::handleEvent):

  • bindings/js/JSCustomPositionCallback.h:
  • bindings/js/JSCustomPositionErrorCallback.cpp:

(WebCore::JSCustomPositionErrorCallback::JSCustomPositionErrorCallback):
(WebCore::JSCustomPositionErrorCallback::handleEvent):

  • bindings/js/JSCustomPositionErrorCallback.h:
  • bindings/js/JSCustomSQLStatementCallback.cpp:

(WebCore::JSCustomSQLStatementCallback::JSCustomSQLStatementCallback):
(WebCore::JSCustomSQLStatementCallback::~JSCustomSQLStatementCallback):
(WebCore::JSCustomSQLStatementCallback::handleEvent):

  • bindings/js/JSCustomSQLStatementCallback.h:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:

(WebCore::JSCustomSQLStatementErrorCallback::JSCustomSQLStatementErrorCallback):
(WebCore::JSCustomSQLStatementErrorCallback::~JSCustomSQLStatementErrorCallback):
(WebCore::JSCustomSQLStatementErrorCallback::handleEvent):

  • bindings/js/JSCustomSQLStatementErrorCallback.h:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:

(WebCore::JSCustomSQLTransactionCallback::JSCustomSQLTransactionCallback):
(WebCore::JSCustomSQLTransactionCallback::~JSCustomSQLTransactionCallback):
(WebCore::JSCustomSQLTransactionCallback::handleEvent):

  • bindings/js/JSCustomSQLTransactionCallback.h:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:

(WebCore::JSCustomSQLTransactionErrorCallback::JSCustomSQLTransactionErrorCallback):
(WebCore::JSCustomSQLTransactionErrorCallback::~JSCustomSQLTransactionErrorCallback):
(WebCore::JSCustomSQLTransactionErrorCallback::handleEvent):

  • bindings/js/JSCustomSQLTransactionErrorCallback.h:
  • bindings/js/JSCustomVoidCallback.cpp:

(WebCore::JSCustomVoidCallback::JSCustomVoidCallback):
(WebCore::JSCustomVoidCallback::~JSCustomVoidCallback):
(WebCore::JSCustomVoidCallback::handleEvent):

  • bindings/js/JSCustomVoidCallback.h:
  • storage/Database.cpp:

(WebCore::Database::Database):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r48854 r49280  
    981981}
    982982
    983 void Heap::setGCProtectNeedsLocking()
    984 {
    985     // Most clients do not need to call this, with the notable exception of WebCore.
    986     // Clients that use shared heap have JSLock protection, while others are supposed
    987     // to do explicit locking. WebCore violates this contract in Database code,
    988     // which calls gcUnprotect from a secondary thread.
    989     if (!m_protectedValuesMutex)
    990         m_protectedValuesMutex.set(new Mutex);
    991 }
    992 
    993983void Heap::protect(JSValue k)
    994984{
     
    999989        return;
    1000990
    1001     if (m_protectedValuesMutex)
    1002         m_protectedValuesMutex->lock();
    1003 
    1004991    m_protectedValues.add(k.asCell());
    1005 
    1006     if (m_protectedValuesMutex)
    1007         m_protectedValuesMutex->unlock();
    1008992}
    1009993
     
    10161000        return;
    10171001
    1018     if (m_protectedValuesMutex)
    1019         m_protectedValuesMutex->lock();
    1020 
    10211002    m_protectedValues.remove(k.asCell());
    1022 
    1023     if (m_protectedValuesMutex)
    1024         m_protectedValuesMutex->unlock();
    10251003}
    10261004
    10271005void Heap::markProtectedObjects(MarkStack& markStack)
    10281006{
    1029     if (m_protectedValuesMutex)
    1030         m_protectedValuesMutex->lock();
    1031 
    10321007    ProtectCountSet::iterator end = m_protectedValues.end();
    10331008    for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it) {
     
    10351010        markStack.drain();
    10361011    }
    1037 
    1038     if (m_protectedValuesMutex)
    1039         m_protectedValuesMutex->unlock();
    10401012}
    10411013
     
    12291201size_t Heap::protectedGlobalObjectCount()
    12301202{
    1231     if (m_protectedValuesMutex)
    1232         m_protectedValuesMutex->lock();
    1233 
    12341203    size_t count = 0;
    12351204    if (JSGlobalObject* head = m_globalData->head) {
     
    12421211    }
    12431212
    1244     if (m_protectedValuesMutex)
    1245         m_protectedValuesMutex->unlock();
    1246 
    12471213    return count;
    12481214}
     
    12501216size_t Heap::protectedObjectCount()
    12511217{
    1252     if (m_protectedValuesMutex)
    1253         m_protectedValuesMutex->lock();
    1254 
    1255     size_t result = m_protectedValues.size();
    1256 
    1257     if (m_protectedValuesMutex)
    1258         m_protectedValuesMutex->unlock();
    1259 
    1260     return result;
     1218    return m_protectedValues.size();
    12611219}
    12621220
     
    12801238    HashCountedSet<const char*>* counts = new HashCountedSet<const char*>;
    12811239
    1282     if (m_protectedValuesMutex)
    1283         m_protectedValuesMutex->lock();
    1284 
    12851240    ProtectCountSet::iterator end = m_protectedValues.end();
    12861241    for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it)
    12871242        counts->add(typeName(it->first));
    12881243
    1289     if (m_protectedValuesMutex)
    1290         m_protectedValuesMutex->unlock();
    1291 
    12921244    return counts;
    12931245}
Note: See TracChangeset for help on using the changeset viewer.