Changeset 164018 in webkit


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

No need to save reservedZoneSize when dropping the JSLock.
<https://webkit.org/b/128719>

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

The reservedZoneSize does not change due to the VM being run on a different
thread. Hence, there is no need to save and restore its value. Instead of
calling updateReservedZoneSize() to update the stack limit, we now call
setStackPointerAtVMEntry() to do the job. setStackPointerAtVMEntry()
will update the stackPointerAtVMEntry and delegate to updateStackLimit() to
update the stack limit based on the new stackPointerAtVMEntry.

  • runtime/ErrorHandlingScope.cpp:

(JSC::ErrorHandlingScope::ErrorHandlingScope):
(JSC::ErrorHandlingScope::~ErrorHandlingScope):

  • Previously, we initialize stackPointerAtVMEntry in VMEntryScope. This means that the stackPointerAtVMEntry may not be initialize when we instantiate the ErrorHandlingScope. And so, we needed to initialize the stackPointerAtVMEntry in the ErrorHandlingScope constructor if it's not already initialized.

Now that we initialize the stackPointerAtVMEntry when we lock the VM JSLock,
we are guaranteed that it will be initialized by the time we instantiate
the ErrorHandlingScope. Hence, we can change the ErrorHandlingScope code
to just assert that the stackPointerAtVMEntry is initialized instead.

  • runtime/InitializeThreading.cpp:

(JSC::initializeThreading):

  • We no longer need to save the reservedZoneSize. Remove the related code.
  • runtime/JSLock.cpp:

(JSC::JSLock::lock):

  • When we grab the JSLock mutex for the first time, there is no reason why the stackPointerAtVMEntry should be initialized. By definition, grabbing the lock for the first time equates to entering the VM for the first time. Hence, we can just assert that stackPointerAtVMEntry is uninitialized, and initialize it unconditionally.

The only exception to this is if we're locking to regrab the JSLock in
grabAllLocks(), but grabAllLocks() will take care of restoring the
stackPointerAtVMEntry in that case after lock() returns. stackPointerAtVMEntry
should still be 0 when we've just locked the JSLock. So, the above assertion
always holds true.

Note: VM::setStackPointerAtVMEntry() will take care of calling
VM::updateStackLimit() based on the new stackPointerAtVMEntry.

  • There is no need to save the reservedZoneSize. The reservedZoneSize is set to Options::reservedZoneSize() when the VM is initialized. Thereafter, the ErrorHandlingScope will change it to Options::errorModeReservedZoneSize() when we're handling an error, and it will restore it afterwards. There is no other reason we should be changing the reservedZoneSize. Hence, we can remove the unnecessary code to save it here.

(JSC::JSLock::unlock):

  • Similarly, when the lockCount reaches 0 in unlock(), it is synonymous with exiting the VM. Hence, we should just clear the stackPointerAtVMEntry and update the stackLimit. Exiting the VM should have no effect on the VM reservedZoneSize. Hence, we can remove the unnecessary code to "restore" it.

(JSC::JSLock::dropAllLocks):

  • When dropping locks, we do not need to save the reservedZoneSize because the reservedZoneSize should remain the same regardless of which thread we are executing JS on. Hence, we can remove the unnecessary code to save the reservedZoneSize here.

(JSC::JSLock::grabAllLocks):

  • When re-grabbing locks, restoring the stackPointerAtVMEntry via VM::setStackPointerAtVMEntry() will take care of updating the stack limit. As explained above, there's no need to save the reservedZoneSize. Hence, there's no need to "restore" it here.
  • runtime/VM.cpp:

(JSC::VM::VM):
(JSC::VM::setStackPointerAtVMEntry):

  • Sets the stackPointerAtVMEntry and delegates to updateStackLimit() to update the stack limit based on the new stackPointerAtVMEntry.

(JSC::VM::updateStackLimit):

  • runtime/VM.h:

(JSC::VM::stackPointerAtVMEntry):

  • Renamed stackPointerAtVMEntry to m_stackPointerAtVMEntry and made it private. Added a stackPointerAtVMEntry() function to read the value.

Source/WTF:

  • wtf/WTFThreadData.cpp:

(WTF::WTFThreadData::WTFThreadData):

  • wtf/WTFThreadData.h:
  • removed unnneeded m_savedReservedZoneSize.
Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r164009 r164018  
     12014-02-12  Mark Lam  <mark.lam@apple.com>
     2
     3        No need to save reservedZoneSize when dropping the JSLock.
     4        <https://webkit.org/b/128719>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        The reservedZoneSize does not change due to the VM being run on a different
     9        thread. Hence, there is no need to save and restore its value. Instead of
     10        calling updateReservedZoneSize() to update the stack limit, we now call
     11        setStackPointerAtVMEntry() to do the job. setStackPointerAtVMEntry()
     12        will update the stackPointerAtVMEntry and delegate to updateStackLimit() to
     13        update the stack limit based on the new stackPointerAtVMEntry.
     14
     15        * runtime/ErrorHandlingScope.cpp:
     16        (JSC::ErrorHandlingScope::ErrorHandlingScope):
     17        (JSC::ErrorHandlingScope::~ErrorHandlingScope):
     18        - Previously, we initialize stackPointerAtVMEntry in VMEntryScope. This
     19          means that the stackPointerAtVMEntry may not be initialize when we
     20          instantiate the ErrorHandlingScope. And so, we needed to initialize the
     21          stackPointerAtVMEntry in the ErrorHandlingScope constructor if it's not
     22          already initialized.
     23
     24          Now that we initialize the stackPointerAtVMEntry when we lock the VM JSLock,
     25          we are guaranteed that it will be initialized by the time we instantiate
     26          the ErrorHandlingScope. Hence, we can change the ErrorHandlingScope code
     27          to just assert that the stackPointerAtVMEntry is initialized instead.
     28
     29        * runtime/InitializeThreading.cpp:
     30        (JSC::initializeThreading):
     31        - We no longer need to save the reservedZoneSize. Remove the related code.
     32
     33        * runtime/JSLock.cpp:
     34        (JSC::JSLock::lock):
     35        - When we grab the JSLock mutex for the first time, there is no reason why
     36          the stackPointerAtVMEntry should be initialized. By definition, grabbing
     37          the lock for the first time equates to entering the VM for the first time.
     38          Hence, we can just assert that stackPointerAtVMEntry is uninitialized,
     39          and initialize it unconditionally.
     40
     41          The only exception to this is if we're locking to regrab the JSLock in
     42          grabAllLocks(), but grabAllLocks() will take care of restoring the
     43          stackPointerAtVMEntry in that case after lock() returns. stackPointerAtVMEntry
     44          should still be 0 when we've just locked the JSLock. So, the above assertion
     45          always holds true.
     46
     47          Note: VM::setStackPointerAtVMEntry() will take care of calling
     48          VM::updateStackLimit() based on the new stackPointerAtVMEntry.
     49
     50        - There is no need to save the reservedZoneSize. The reservedZoneSize is
     51          set to Options::reservedZoneSize() when the VM is initialized. Thereafter,
     52          the ErrorHandlingScope will change it to Options::errorModeReservedZoneSize()
     53          when we're handling an error, and it will restore it afterwards. There is
     54          no other reason we should be changing the reservedZoneSize. Hence, we can
     55          remove the unnecessary code to save it here.
     56
     57        (JSC::JSLock::unlock):
     58        - Similarly, when the lockCount reaches 0 in unlock(), it is synonymous with
     59          exiting the VM. Hence, we should just clear the stackPointerAtVMEntry and
     60          update the stackLimit. Exiting the VM should have no effect on the VM
     61          reservedZoneSize. Hence, we can remove the unnecessary code to "restore" it.
     62
     63        (JSC::JSLock::dropAllLocks):
     64        - When dropping locks, we do not need to save the reservedZoneSize because
     65          the reservedZoneSize should remain the same regardless of which thread
     66          we are executing JS on. Hence, we can remove the unnecessary code to save
     67          the reservedZoneSize here.
     68
     69        (JSC::JSLock::grabAllLocks):
     70        - When re-grabbing locks, restoring the stackPointerAtVMEntry via
     71          VM::setStackPointerAtVMEntry() will take care of updating the stack limit.
     72          As explained above, there's no need to save the reservedZoneSize. Hence,
     73          there's no need to "restore" it here.
     74
     75        * runtime/VM.cpp:
     76        (JSC::VM::VM):
     77        (JSC::VM::setStackPointerAtVMEntry):
     78        - Sets the stackPointerAtVMEntry and delegates to updateStackLimit() to update
     79          the stack limit based on the new stackPointerAtVMEntry.
     80        (JSC::VM::updateStackLimit):
     81        * runtime/VM.h:
     82        (JSC::VM::stackPointerAtVMEntry):
     83        - Renamed stackPointerAtVMEntry to m_stackPointerAtVMEntry and made it private.
     84          Added a stackPointerAtVMEntry() function to read the value.
     85
    1862014-02-12  Mark Hahnenberg  <mhahnenberg@apple.com>
    287
  • trunk/Source/JavaScriptCore/runtime/ErrorHandlingScope.cpp

    r163964 r164018  
    3636    : m_vm(vm)
    3737{
    38     if (!m_vm.stackPointerAtVMEntry)
    39         m_vm.stackPointerAtVMEntry = this;
     38    RELEASE_ASSERT(m_vm.stackPointerAtVMEntry());
    4039    size_t newReservedZoneSize = Options::errorModeReservedZoneSize();
    4140    m_savedReservedZoneSize = m_vm.updateReservedZoneSize(newReservedZoneSize);
     
    4746ErrorHandlingScope::~ErrorHandlingScope()
    4847{
    49     if (m_vm.stackPointerAtVMEntry == this)
    50         m_vm.stackPointerAtVMEntry = nullptr;
     48    RELEASE_ASSERT(m_vm.stackPointerAtVMEntry());
    5149    m_vm.updateReservedZoneSize(m_savedReservedZoneSize);
    5250#if ENABLE(LLINT_C_LOOP)
  • trunk/Source/JavaScriptCore/runtime/InitializeThreading.cpp

    r163214 r164018  
    7474#endif
    7575        WTFThreadData& threadData = wtfThreadData();
    76        
    7776        threadData.setSavedLastStackTop(threadData.stack().origin());
    78         threadData.setSavedReservedZoneSize(Options::reservedZoneSize());
    7977    });
    8078}
  • trunk/Source/JavaScriptCore/runtime/JSLock.cpp

    r163964 r164018  
    124124    WTFThreadData& threadData = wtfThreadData();
    125125
    126     if (!m_vm->stackPointerAtVMEntry) {
    127         void* p = &p;
    128         m_vm->stackPointerAtVMEntry = p; // A proxy for the current stack pointer.
    129         threadData.setSavedReservedZoneSize(m_vm->updateReservedZoneSize(Options::reservedZoneSize()));
    130     }
     126    RELEASE_ASSERT(!m_vm->stackPointerAtVMEntry());
     127    void* p = &p; // A proxy for the current stack pointer.
     128    m_vm->setStackPointerAtVMEntry(p);
    131129
    132130    m_vm->setLastStackTop(threadData.savedLastStackTop());
     
    146144
    147145    if (!m_lockCount) {
    148         if (m_vm) {
    149             m_vm->stackPointerAtVMEntry = nullptr;
    150             m_vm->updateReservedZoneSize(wtfThreadData().savedReservedZoneSize());
    151         }
     146        if (m_vm)
     147            m_vm->setStackPointerAtVMEntry(nullptr);
    152148        setOwnerThread(0);
    153149        m_lock.unlock();
     
    186182
    187183    WTFThreadData& threadData = wtfThreadData();
    188     threadData.setSavedStackPointerAtVMEntry(m_vm->stackPointerAtVMEntry);
     184    threadData.setSavedStackPointerAtVMEntry(m_vm->stackPointerAtVMEntry());
    189185    threadData.setSavedLastStackTop(m_vm->lastStackTop());
    190     threadData.setSavedReservedZoneSize(m_vm->reservedZoneSize());
    191186
    192187    unsigned droppedLockCount = m_lockCount;
     
    217212
    218213    WTFThreadData& threadData = wtfThreadData();
    219     m_vm->stackPointerAtVMEntry = threadData.savedStackPointerAtVMEntry();
     214    m_vm->setStackPointerAtVMEntry(threadData.savedStackPointerAtVMEntry());
    220215    m_vm->setLastStackTop(threadData.savedLastStackTop());
    221     m_vm->updateReservedZoneSize(threadData.savedReservedZoneSize());
    222216}
    223217
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r163964 r164018  
    174174    , clientData(0)
    175175    , topCallFrame(CallFrame::noCaller())
    176     , stackPointerAtVMEntry(0)
    177176    , arrayConstructorTable(adoptPtr(new HashTable(JSC::arrayConstructorTable)))
    178177    , arrayPrototypeTable(adoptPtr(new HashTable(JSC::arrayPrototypeTable)))
     
    224223    , m_initializingObjectClass(0)
    225224#endif
     225    , m_stackPointerAtVMEntry(0)
    226226    , m_stackLimit(0)
    227227#if ENABLE(LLINT_C_LOOP)
     
    733733}
    734734
     735void VM::setStackPointerAtVMEntry(void* sp)
     736{
     737    m_stackPointerAtVMEntry = sp;
     738    updateStackLimit();
     739}
     740
    735741size_t VM::updateReservedZoneSize(size_t reservedZoneSize)
    736742{
     
    745751inline void VM::updateStackLimit()
    746752{
    747     if (stackPointerAtVMEntry) {
     753    if (m_stackPointerAtVMEntry) {
    748754        ASSERT(wtfThreadData().stack().isGrowingDownward());
    749         char* startOfStack = reinterpret_cast<char*>(stackPointerAtVMEntry);
     755        char* startOfStack = reinterpret_cast<char*>(m_stackPointerAtVMEntry);
    750756#if ENABLE(FTL_JIT)
    751757        m_stackLimit = wtfThreadData().stack().recursionLimit(startOfStack, Options::maxPerThreadStackUsage(), m_reservedZoneSize + m_largestFTLStackSize);
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r163964 r164018  
    231231        ClientData* clientData;
    232232        ExecState* topCallFrame;
    233         void* stackPointerAtVMEntry;
    234233        Watchdog watchdog;
    235234
     
    380379        JS_EXPORT_PRIVATE JSObject* throwException(ExecState*, JSObject*);
    381380       
     381        void* stackPointerAtVMEntry() const { return m_stackPointerAtVMEntry; }
     382        void setStackPointerAtVMEntry(void*);
     383
    382384        size_t reservedZoneSize() const { return m_reservedZoneSize; }
    383385        size_t updateReservedZoneSize(size_t reservedZoneSize);
     
    530532        const ClassInfo* m_initializingObjectClass;
    531533#endif
     534        void* m_stackPointerAtVMEntry;
    532535        size_t m_reservedZoneSize;
    533536#if ENABLE(LLINT_C_LOOP)
  • trunk/Source/WTF/ChangeLog

    r163887 r164018  
     12014-02-12  Mark Lam  <mark.lam@apple.com>
     2
     3        No need to save reservedZoneSize when dropping the JSLock.
     4        <https://webkit.org/b/128719>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * wtf/WTFThreadData.cpp:
     9        (WTF::WTFThreadData::WTFThreadData):
     10        * wtf/WTFThreadData.h:
     11        - removed unnneeded m_savedReservedZoneSize.
     12
    1132014-02-11  Mark Hahnenberg  <mhahnenberg@apple.com>
    214
  • trunk/Source/WTF/wtf/WTFThreadData.cpp

    r163214 r164018  
    5252    , m_savedStackPointerAtVMEntry(0)
    5353    , m_savedLastStackTop(stack().origin())
    54     , m_savedReservedZoneSize(0)
    5554{
    5655#if USE(WEB_THREAD)
  • trunk/Source/WTF/wtf/WTFThreadData.h

    r163214 r164018  
    127127    }
    128128
    129     size_t savedReservedZoneSize()
    130     {
    131         return m_savedReservedZoneSize;
    132     }
    133 
    134     void setSavedReservedZoneSize(size_t reservedZoneSize)
    135     {
    136         m_savedReservedZoneSize = reservedZoneSize;
    137     }
    138 
    139129    void* m_apiData;
    140130
     
    151141    void* m_savedStackPointerAtVMEntry;
    152142    void* m_savedLastStackTop;
    153     size_t m_savedReservedZoneSize;
    154143
    155144    static WTF_EXPORTDATA ThreadSpecific<WTFThreadData>* staticData;
Note: See TracChangeset for help on using the changeset viewer.