Changeset 163820 in webkit


Ignore:
Timestamp:
Feb 10, 2014 2:27:10 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

Change JSLock::dropAllLocks() and friends to use lock() and unlock().
<https://webkit.org/b/128451>

Reviewed by Geoffrey Garen.

Currently, JSLock's dropAllLocks(), dropAllLocksUnconditionally(), and
grabAllLocks() implement locking / unlocking by duplicating the code from
lock() and unlock(). Instead, they should just call lock() and unlock().

  • runtime/JSLock.cpp:

(JSC::JSLock::lock):
(JSC::JSLock::unlock):

  • Modified lock() and unlock() into a version that takes an entry count to lock / unlock. The previous lock() and unlock() now calls these new versions with an entry count of 1.

(JSC::JSLock::dropAllLocks):
(JSC::JSLock::dropAllLocksUnconditionally):
(JSC::JSLock::grabAllLocks):

  • Delegate to unlock() and lock() instead of duplicating the lock / unlock code.
  • There a some differences with calling lock() instead of duplicating its code in grabAllLock() i.e. lock() does the following additional work:
  1. lock() does a re-entry check that is not needed by grabAllLocks(). However, this is effectively a no-op since we never own the JSLock before calling grabAllLocks().
  1. set VM stackPointerAtVMEntry.
  2. update VM stackLimit and reservedZoneSize.
  3. set VM lastStackTop. These 3 steps are just busy work which are also effective no-ops because immediately after lock() returns, grabAllLocks() will write over those values with their saved versions in the threadData.
  • runtime/JSLock.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r163815 r163820  
     12014-02-10  Mark Lam  <mark.lam@apple.com>
     2
     3        Change JSLock::dropAllLocks() and friends to use lock() and unlock().
     4        <https://webkit.org/b/128451>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Currently, JSLock's dropAllLocks(), dropAllLocksUnconditionally(), and
     9        grabAllLocks() implement locking / unlocking by duplicating the code from
     10        lock() and unlock(). Instead, they should just call lock() and unlock().
     11
     12        * runtime/JSLock.cpp:
     13        (JSC::JSLock::lock):
     14        (JSC::JSLock::unlock):
     15        - Modified lock() and unlock() into a version that takes an entry count
     16          to lock / unlock. The previous lock() and unlock() now calls these
     17          new versions with an entry count of 1.
     18
     19        (JSC::JSLock::dropAllLocks):
     20        (JSC::JSLock::dropAllLocksUnconditionally):
     21        (JSC::JSLock::grabAllLocks):
     22        - Delegate to unlock() and lock() instead of duplicating the lock / unlock
     23          code.
     24        - There a some differences with calling lock() instead of duplicating its
     25          code in grabAllLock() i.e. lock() does the following additional work:
     26
     27          1. lock() does a re-entry check that is not needed by grabAllLocks().
     28             However, this is effectively a no-op since we never own the JSLock
     29             before calling grabAllLocks().
     30
     31          2. set VM stackPointerAtVMEntry.
     32          3. update VM stackLimit and reservedZoneSize.
     33          4. set VM lastStackTop.
     34             These 3 steps are just busy work which are also effective no-ops
     35             because immediately after lock() returns, grabAllLocks() will write
     36             over those values with their saved versions in the threadData.
     37
     38        * runtime/JSLock.h:
     39
    1402014-02-10  Anders Carlsson  <andersca@apple.com>
    241
  • trunk/Source/JavaScriptCore/runtime/JSLock.cpp

    r163804 r163820  
    101101void JSLock::lock()
    102102{
     103    lock(1);
     104}
     105
     106void JSLock::lock(intptr_t lockCount)
     107{
     108    ASSERT(lockCount > 0);
    103109    ThreadIdentifier currentThread = WTF::currentThread();
    104110    if (currentThreadIsHoldingLock()) {
    105         m_lockCount++;
     111        m_lockCount += lockCount;
    106112        return;
    107113    }
     
    111117    setOwnerThread(currentThread);
    112118    ASSERT(!m_lockCount);
    113     m_lockCount = 1;
     119    m_lockCount = lockCount;
    114120
    115121    WTFThreadData& threadData = wtfThreadData();
     
    126132void JSLock::unlock()
    127133{
     134    unlock(1);
     135}
     136
     137void JSLock::unlock(intptr_t unlockCount)
     138{
    128139    RELEASE_ASSERT(currentThreadIsHoldingLock());
    129 
    130     m_lockCount--;
     140    ASSERT(m_lockCount >= unlockCount);
     141
     142    m_lockCount -= unlockCount;
    131143
    132144    if (!m_lockCount) {
     
    219231
    220232    unsigned droppedLockCount = m_lockCount;
    221     m_lockCount = 0;
    222     if (m_vm) {
    223         m_vm->stackPointerAtVMEntry = nullptr;
    224         m_vm->updateStackLimitWithReservedZoneSize(wtfThreadData().savedReservedZoneSize());
    225     }
    226     setOwnerThread(0);
    227     m_lock.unlock();
     233    unlock(droppedLockCount);
     234
    228235    return droppedLockCount;
    229236}
     
    245252
    246253    unsigned droppedLockCount = m_lockCount;
    247     m_lockCount = 0;
    248     if (m_vm) {
    249         m_vm->stackPointerAtVMEntry = nullptr;
    250         m_vm->updateStackLimitWithReservedZoneSize(wtfThreadData().savedReservedZoneSize());
    251     }
    252     setOwnerThread(0);
    253     m_lock.unlock();
     254    unlock(droppedLockCount);
     255
    254256    return droppedLockCount;
    255257}
     
    262264
    263265    ASSERT(!currentThreadIsHoldingLock());
    264 
    265     m_lock.lock();
    266 
    267     setOwnerThread(WTF::currentThread());
    268     ASSERT(!m_lockCount);
    269     m_lockCount = droppedLockCount;
     266    lock(droppedLockCount);
     267
    270268    --m_lockDropDepth;
    271269
  • trunk/Source/JavaScriptCore/runtime/JSLock.h

    r163804 r163820  
    113113
    114114    private:
     115        void lock(intptr_t lockCount);
     116        void unlock(intptr_t unlockCount);
    115117        void setOwnerThread(ThreadIdentifier owner) { m_ownerThread = owner; }
    116118
Note: See TracChangeset for help on using the changeset viewer.