Changeset 187020 in webkit


Ignore:
Timestamp:
Jul 20, 2015 2:14:10 AM (9 years ago)
Author:
peavo@outlook.com
Message:

JavaScriptCore performance is very bad on Windows
https://bugs.webkit.org/show_bug.cgi?id=146448

Reviewed by Mark Lam.

Source/JavaScriptCore:

Profiling shows that std::this_thread::get_id() is slow on Windows.
Use WTF::currentThread() instead, which calls GetCurrentThreadId().
This is faster on Windows. The issue has been reported to Microsoft,
https://connect.microsoft.com/VisualStudio/feedback/details/1558211.

  • runtime/JSLock.cpp:

(JSC::JSLockHolder::~JSLockHolder):
(JSC::JSLock::JSLock):
(JSC::JSLock::willDestroyVM):
(JSC::JSLock::setExclusiveThread):
(JSC::JSLock::lock):
(JSC::JSLock::unlock):
(JSC::JSLock::currentThreadIsHoldingLock):

  • runtime/JSLock.h:

(JSC::JSLock::vm):
(JSC::JSLock::hasExclusiveThread):
(JSC::JSLock::exclusiveThread):

  • runtime/VM.h:

(JSC::VM::hasExclusiveThread):
(JSC::VM::exclusiveThread):
(JSC::VM::setExclusiveThread):

Source/WebCore:

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::commonVM): Compile fix.

Source/WTF:

Updating the stack bounds is time consuming.
Only update the stack bounds when a new fiber is running.

  • wtf/WTFThreadData.cpp:

(WTF::WTFThreadData::WTFThreadData):

  • wtf/WTFThreadData.h:

(WTF::WTFThreadData::stack):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r187017 r187020  
     12015-07-20  Per Arne Vollan  <peavo@outlook.com>
     2
     3        JavaScriptCore performance is very bad on Windows
     4        https://bugs.webkit.org/show_bug.cgi?id=146448
     5
     6        Reviewed by Mark Lam.
     7
     8        Profiling shows that std::this_thread::get_id() is slow on Windows.
     9        Use WTF::currentThread() instead, which calls GetCurrentThreadId().
     10        This is faster on Windows. The issue has been reported to Microsoft,
     11        https://connect.microsoft.com/VisualStudio/feedback/details/1558211.
     12
     13        * runtime/JSLock.cpp:
     14        (JSC::JSLockHolder::~JSLockHolder):
     15        (JSC::JSLock::JSLock):
     16        (JSC::JSLock::willDestroyVM):
     17        (JSC::JSLock::setExclusiveThread):
     18        (JSC::JSLock::lock):
     19        (JSC::JSLock::unlock):
     20        (JSC::JSLock::currentThreadIsHoldingLock):
     21        * runtime/JSLock.h:
     22        (JSC::JSLock::vm):
     23        (JSC::JSLock::hasExclusiveThread):
     24        (JSC::JSLock::exclusiveThread):
     25        * runtime/VM.h:
     26        (JSC::VM::hasExclusiveThread):
     27        (JSC::VM::exclusiveThread):
     28        (JSC::VM::setExclusiveThread):
     29
    1302015-07-19  Yusuke Suzuki  <utatane.tea@gmail.com>
    231
  • trunk/Source/JavaScriptCore/runtime/JSLock.cpp

    r186966 r187020  
    2727#include "JSObject.h"
    2828#include "JSCInlines.h"
    29 #include <thread>
    3029
    3130namespace JSC {
     
    7978
    8079JSLock::JSLock(VM* vm)
    81     : m_ownerThreadID(std::thread::id())
     80    : m_ownerThreadID(0)
    8281    , m_lockCount(0)
    8382    , m_lockDropDepth(0)
     
    9897}
    9998
    100 void JSLock::setExclusiveThread(std::thread::id threadId)
    101 {
    102     RELEASE_ASSERT(!m_lockCount && m_ownerThreadID == std::thread::id());
    103     m_hasExclusiveThread = (threadId != std::thread::id());
     99void JSLock::setExclusiveThread(ThreadIdentifier threadId)
     100{
     101    RELEASE_ASSERT(!m_lockCount && !m_ownerThreadID);
     102    m_hasExclusiveThread = !!threadId;
    104103    m_ownerThreadID = threadId;
    105104}
     
    120119    if (!m_hasExclusiveThread) {
    121120        m_lock.lock();
    122         m_ownerThreadID = std::this_thread::get_id();
     121        m_ownerThreadID = currentThread();
    123122    }
    124123    ASSERT(!m_lockCount);
     
    168167
    169168        if (!m_hasExclusiveThread) {
    170             m_ownerThreadID = std::thread::id();
     169            m_ownerThreadID = 0;
    171170            m_lock.unlock();
    172171        }
     
    201200bool JSLock::currentThreadIsHoldingLock()
    202201{
    203     ASSERT(!m_hasExclusiveThread || (exclusiveThread() == std::this_thread::get_id()));
     202    ASSERT(!m_hasExclusiveThread || (exclusiveThread() == currentThread()));
    204203    if (m_hasExclusiveThread)
    205204        return !!m_lockCount;
    206     return m_ownerThreadID == std::this_thread::get_id();
     205    return m_ownerThreadID == currentThread();
    207206}
    208207
     
    211210{
    212211    if (m_hasExclusiveThread) {
    213         ASSERT(exclusiveThread() == std::this_thread::get_id());
     212        ASSERT(exclusiveThread() == currentThread());
    214213        return 0;
    215214    }
  • trunk/Source/JavaScriptCore/runtime/JSLock.h

    r173269 r187020  
    2323
    2424#include <mutex>
    25 #include <thread>
    2625#include <wtf/Assertions.h>
    2726#include <wtf/Noncopyable.h>
    2827#include <wtf/RefPtr.h>
    2928#include <wtf/ThreadSafeRefCounted.h>
     29#include <wtf/Threading.h>
    3030#include <wtf/WTFThreadData.h>
    3131
     
    9797
    9898    bool hasExclusiveThread() const { return m_hasExclusiveThread; }
    99     std::thread::id exclusiveThread() const
     99    ThreadIdentifier exclusiveThread() const
    100100    {
    101101        ASSERT(m_hasExclusiveThread);
    102102        return m_ownerThreadID;
    103103    }
    104     JS_EXPORT_PRIVATE void setExclusiveThread(std::thread::id);
     104    JS_EXPORT_PRIVATE void setExclusiveThread(ThreadIdentifier);
    105105    JS_EXPORT_PRIVATE bool currentThreadIsHoldingLock();
    106106
     
    135135
    136136    std::mutex m_lock;
    137     std::thread::id m_ownerThreadID;
     137    ThreadIdentifier m_ownerThreadID;
    138138    intptr_t m_lockCount;
    139139    unsigned m_lockDropDepth;
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r186966 r187020  
    500500
    501501    bool hasExclusiveThread() const { return m_apiLock->hasExclusiveThread(); }
    502     std::thread::id exclusiveThread() const { return m_apiLock->exclusiveThread(); }
    503     void setExclusiveThread(std::thread::id threadId) { m_apiLock->setExclusiveThread(threadId); }
     502    ThreadIdentifier exclusiveThread() const { return m_apiLock->exclusiveThread(); }
     503    void setExclusiveThread(ThreadIdentifier threadId) { m_apiLock->setExclusiveThread(threadId); }
    504504
    505505    JS_EXPORT_PRIVATE void resetDateCache();
  • trunk/Source/WTF/ChangeLog

    r187019 r187020  
     12015-07-20  Per Arne Vollan  <peavo@outlook.com>
     2
     3        JavaScriptCore performance is very bad on Windows
     4        https://bugs.webkit.org/show_bug.cgi?id=146448
     5
     6        Reviewed by Mark Lam.
     7
     8        Updating the stack bounds is time consuming.
     9        Only update the stack bounds when a new fiber is running.
     10
     11        * wtf/WTFThreadData.cpp:
     12        (WTF::WTFThreadData::WTFThreadData):
     13        * wtf/WTFThreadData.h:
     14        (WTF::WTFThreadData::stack):
     15
    1162015-07-20  Julien Brianceau  <julien.brianceau@gmail.com>
    217
  • trunk/Source/WTF/wtf/WTFThreadData.cpp

    r165982 r187020  
    5151    , m_savedStackPointerAtVMEntry(0)
    5252    , m_savedLastStackTop(stack().origin())
     53#if OS(WINDOWS)
     54    , m_lastFiber(nullptr)
     55#endif
    5356{
    5457    AtomicStringTable::create(*this);
  • trunk/Source/WTF/wtf/WTFThreadData.h

    r183697 r187020  
    8484        // See https://bugs.webkit.org/show_bug.cgi?id=102411
    8585#if OS(WINDOWS)
    86         m_stackBounds = StackBounds::currentThreadStackBounds();
     86        void* currentFiber = GetCurrentFiber();
     87        if (currentFiber != m_lastFiber) {
     88            m_stackBounds = StackBounds::currentThreadStackBounds();
     89            m_lastFiber = currentFiber;
     90        }
    8791#endif
    8892        return m_stackBounds;
     
    129133    void* m_savedStackPointerAtVMEntry;
    130134    void* m_savedLastStackTop;
     135#if OS(WINDOWS)
     136    void* m_lastFiber;
     137#endif
    131138
    132139#if USE(PTHREAD_GETSPECIFIC_DIRECT)
  • trunk/Source/WebCore/ChangeLog

    r187018 r187020  
     12015-07-20  Per Arne Vollan  <peavo@outlook.com>
     2
     3        JavaScriptCore performance is very bad on Windows
     4        https://bugs.webkit.org/show_bug.cgi?id=146448
     5
     6        Reviewed by Mark Lam.
     7
     8        * bindings/js/JSDOMWindowBase.cpp:
     9        (WebCore::JSDOMWindowBase::commonVM): Compile fix.
     10
    1112015-07-19  Tim Horton  <timothy_horton@apple.com>
    212
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r185721 r187020  
    204204        vm = &VM::createLeaked(LargeHeap).leakRef();
    205205#if !PLATFORM(IOS)
    206         vm->setExclusiveThread(std::this_thread::get_id());
     206        vm->setExclusiveThread(currentThread());
    207207#else
    208208        vm->heap.setFullActivityCallback(WebSafeFullGCActivityCallback::create(&vm->heap));
Note: See TracChangeset for help on using the changeset viewer.