Changeset 179609 in webkit


Ignore:
Timestamp:
Feb 4, 2015, 10:00:05 AM (10 years ago)
Author:
mark.lam@apple.com
Message:

Remove concept of makeUsableFromMultipleThreads().
<https://webkit.org/b/141221>

Reviewed by Mark Hahnenberg.

Source/JavaScriptCore:

Currently, we rely on VM::makeUsableFromMultipleThreads() being called before we
start acquiring the JSLock and entering the VM from different threads.
Acquisition of the JSLock will register the acquiring thread with the VM's thread
registry if not already registered. However, it will only do this if the VM's
thread specific key has been initialized by makeUsableFromMultipleThreads().

This is fragile, and also does not read intuitively because one would expect to
acquire the JSLock before calling any methods on the VM. This is exactly what
JSGlobalContextCreateInGroup() did (i.e. acquire the lock before calling
makeUsableFromMultipleThreads()), but is wrong. The result is that the invoking
thread will not have been registered with the VM during that first entry into
the VM.

The fix is to make it so that we initialize the VM's thread specific key on
construction of the VM's MachineThreads registry instead of relying on
makeUsableFromMultipleThreads() being called. With this, we can eliminate
makeUsableFromMultipleThreads() altogether.

Performance results are neutral in aggregate.

  • API/JSContextRef.cpp:

(JSGlobalContextCreateInGroup):

  • heap/MachineStackMarker.cpp:

(JSC::MachineThreads::MachineThreads):
(JSC::MachineThreads::~MachineThreads):
(JSC::MachineThreads::addCurrentThread):
(JSC::MachineThreads::removeThread):
(JSC::MachineThreads::gatherConservativeRoots):
(JSC::MachineThreads::makeUsableFromMultipleThreads): Deleted.

  • heap/MachineStackMarker.h:
  • runtime/VM.cpp:

(JSC::VM::sharedInstance):

  • runtime/VM.h:

(JSC::VM::makeUsableFromMultipleThreads): Deleted.

Source/WebCore:

No new tests.

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::commonVM):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSContextRef.cpp

    r176973 r179609  
    139139
    140140    JSLockHolder locker(vm.get());
    141     vm->makeUsableFromMultipleThreads();
    142141
    143142    if (!globalObjectClass) {
  • trunk/Source/JavaScriptCore/ChangeLog

    r179599 r179609  
     12015-02-04  Mark Lam  <mark.lam@apple.com>
     2
     3        Remove concept of makeUsableFromMultipleThreads().
     4        <https://webkit.org/b/141221>
     5
     6        Reviewed by Mark Hahnenberg.
     7
     8        Currently, we rely on VM::makeUsableFromMultipleThreads() being called before we
     9        start acquiring the JSLock and entering the VM from different threads.
     10        Acquisition of the JSLock will register the acquiring thread with the VM's thread
     11        registry if not already registered.  However, it will only do this if the VM's
     12        thread specific key has been initialized by makeUsableFromMultipleThreads().
     13
     14        This is fragile, and also does not read intuitively because one would expect to
     15        acquire the JSLock before calling any methods on the VM.  This is exactly what
     16        JSGlobalContextCreateInGroup() did (i.e. acquire the lock before calling
     17        makeUsableFromMultipleThreads()), but is wrong.  The result is that the invoking
     18        thread will not have been registered with the VM during that first entry into
     19        the VM.
     20
     21        The fix is to make it so that we initialize the VM's thread specific key on
     22        construction of the VM's MachineThreads registry instead of relying on
     23        makeUsableFromMultipleThreads() being called.  With this, we can eliminate
     24        makeUsableFromMultipleThreads() altogether.
     25
     26        Performance results are neutral in aggregate.
     27
     28        * API/JSContextRef.cpp:
     29        (JSGlobalContextCreateInGroup):
     30        * heap/MachineStackMarker.cpp:
     31        (JSC::MachineThreads::MachineThreads):
     32        (JSC::MachineThreads::~MachineThreads):
     33        (JSC::MachineThreads::addCurrentThread):
     34        (JSC::MachineThreads::removeThread):
     35        (JSC::MachineThreads::gatherConservativeRoots):
     36        (JSC::MachineThreads::makeUsableFromMultipleThreads): Deleted.
     37        * heap/MachineStackMarker.h:
     38        * runtime/VM.cpp:
     39        (JSC::VM::sharedInstance):
     40        * runtime/VM.h:
     41        (JSC::VM::makeUsableFromMultipleThreads): Deleted.
     42
    1432015-02-04  Chris Dumez  <cdumez@apple.com>
    244
  • trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp

    r179576 r179609  
    124124{
    125125    UNUSED_PARAM(heap);
     126    threadSpecificKeyCreate(&m_threadSpecific, removeThread);
    126127}
    127128
    128129MachineThreads::~MachineThreads()
    129130{
    130     if (m_threadSpecific)
    131         threadSpecificKeyDelete(m_threadSpecific);
     131    threadSpecificKeyDelete(m_threadSpecific);
    132132
    133133    MutexLocker registeredThreadsLock(m_registeredThreadsMutex);
     
    161161}
    162162
    163 void MachineThreads::makeUsableFromMultipleThreads()
    164 {
    165     if (m_threadSpecific)
     163void MachineThreads::addCurrentThread()
     164{
     165    ASSERT(!m_heap->vm()->hasExclusiveThread() || m_heap->vm()->exclusiveThread() == std::this_thread::get_id());
     166
     167    if (threadSpecificGet(m_threadSpecific)) {
     168        ASSERT(threadSpecificGet(m_threadSpecific) == this);
    166169        return;
    167 
    168     threadSpecificKeyCreate(&m_threadSpecific, removeThread);
    169 }
    170 
    171 void MachineThreads::addCurrentThread()
    172 {
    173     ASSERT(!m_heap->vm()->hasExclusiveThread() || m_heap->vm()->exclusiveThread() == std::this_thread::get_id());
    174 
    175     if (!m_threadSpecific || threadSpecificGet(m_threadSpecific))
    176         return;
     170    }
    177171
    178172    threadSpecificSet(m_threadSpecific, this);
     
    187181void MachineThreads::removeThread(void* p)
    188182{
    189     if (p)
    190         static_cast<MachineThreads*>(p)->removeCurrentThread();
     183    static_cast<MachineThreads*>(p)->removeCurrentThread();
    191184}
    192185
     
    522515    gatherFromCurrentThread(conservativeRoots, jitStubRoutines, codeBlocks, stackCurrent, currentThreadRegisters);
    523516
    524     if (!m_threadSpecific)
    525         return;
    526 
    527517    size_t size;
    528518    size_t capacity = 0;
  • trunk/Source/JavaScriptCore/heap/MachineStackMarker.h

    r179576 r179609  
    4545        void gatherConservativeRoots(ConservativeRoots&, JITStubRoutineSet&, CodeBlockSet&, void* stackCurrent, RegisterState& registers);
    4646
    47         JS_EXPORT_PRIVATE void makeUsableFromMultipleThreads();
    4847        JS_EXPORT_PRIVATE void addCurrentThread(); // Only needs to be called by clients that can use the same heap from multiple threads.
    4948
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r179478 r179609  
    358358    GlobalJSLock globalLock;
    359359    VM*& instance = sharedInstanceInternal();
    360     if (!instance) {
     360    if (!instance)
    361361        instance = adoptRef(new VM(APIShared, SmallHeap)).leakRef();
    362         instance->makeUsableFromMultipleThreads();
    363     }
    364362    return *instance;
    365363}
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r179478 r179609  
    218218    JS_EXPORT_PRIVATE ~VM();
    219219
    220     void makeUsableFromMultipleThreads() { heap.machineThreads().makeUsableFromMultipleThreads(); }
    221 
    222220private:
    223221    RefPtr<JSLock> m_apiLock;
  • trunk/Source/WebCore/ChangeLog

    r179604 r179609  
     12015-02-04  Mark Lam  <mark.lam@apple.com>
     2
     3        Remove concept of makeUsableFromMultipleThreads().
     4        <https://webkit.org/b/141221>
     5
     6        Reviewed by Mark Hahnenberg.
     7
     8        No new tests.
     9
     10        * bindings/js/JSDOMWindowBase.cpp:
     11        (WebCore::JSDOMWindowBase::commonVM):
     12
    1132015-02-04  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r178820 r179609  
    213213#endif
    214214        vm->heap.setIncrementalSweeper(std::make_unique<WebSafeIncrementalSweeper>(&vm->heap));
    215         vm->makeUsableFromMultipleThreads();
    216215        vm->heap.machineThreads().addCurrentThread();
    217216#endif
Note: See TracChangeset for help on using the changeset viewer.