Changeset 244497 in webkit


Ignore:
Timestamp:
Apr 21, 2019 11:44:25 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[bmalloc] Use StaticPerProcess' mutex as bmalloc::Heap does with PerProcess
https://bugs.webkit.org/show_bug.cgi?id=197135

Reviewed by Darin Adler.

This patch leverages StaticPerProcess::mutex() for per process instance's lock in various classes,
as Heap does with PerProcess::mutex().

  • bmalloc/AllIsoHeaps.cpp:

(bmalloc::AllIsoHeaps::add):
(bmalloc::AllIsoHeaps::head):

  • bmalloc/AllIsoHeaps.h:
  • bmalloc/CryptoRandom.cpp:

(bmalloc::ARC4RandomNumberGenerator::randomValues):

  • bmalloc/DebugHeap.cpp:

(bmalloc::DebugHeap::memalignLarge):
(bmalloc::DebugHeap::freeLarge):

  • bmalloc/DebugHeap.h:
  • bmalloc/Scavenger.cpp:

(bmalloc::Scavenger::run):
(bmalloc::Scavenger::runSoon):
(bmalloc::Scavenger::scheduleIfUnderMemoryPressure):
(bmalloc::Scavenger::schedule):
(bmalloc::Scavenger::timeSinceLastFullScavenge):
(bmalloc::Scavenger::scavenge):
(bmalloc::Scavenger::threadRunLoop):

  • bmalloc/Scavenger.h:
Location:
trunk/Source/bmalloc
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r244481 r244497  
     12019-04-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [bmalloc] Use StaticPerProcess' mutex as bmalloc::Heap does with PerProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=197135
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch leverages StaticPerProcess::mutex() for per process instance's lock in various classes,
     9        as Heap does with PerProcess::mutex().
     10
     11        * bmalloc/AllIsoHeaps.cpp:
     12        (bmalloc::AllIsoHeaps::add):
     13        (bmalloc::AllIsoHeaps::head):
     14        * bmalloc/AllIsoHeaps.h:
     15        * bmalloc/CryptoRandom.cpp:
     16        (bmalloc::ARC4RandomNumberGenerator::randomValues):
     17        * bmalloc/DebugHeap.cpp:
     18        (bmalloc::DebugHeap::memalignLarge):
     19        (bmalloc::DebugHeap::freeLarge):
     20        * bmalloc/DebugHeap.h:
     21        * bmalloc/Scavenger.cpp:
     22        (bmalloc::Scavenger::run):
     23        (bmalloc::Scavenger::runSoon):
     24        (bmalloc::Scavenger::scheduleIfUnderMemoryPressure):
     25        (bmalloc::Scavenger::schedule):
     26        (bmalloc::Scavenger::timeSinceLastFullScavenge):
     27        (bmalloc::Scavenger::scavenge):
     28        (bmalloc::Scavenger::threadRunLoop):
     29        * bmalloc/Scavenger.h:
     30
    1312019-04-19  Yusuke Suzuki  <ysuzuki@apple.com>
    232
  • trunk/Source/bmalloc/bmalloc/AllIsoHeaps.cpp

    r242938 r244497  
    3636void AllIsoHeaps::add(IsoHeapImplBase* heap)
    3737{
    38     std::lock_guard<Mutex> locker(m_lock);
     38    std::lock_guard<Mutex> locker(mutex());
    3939    heap->m_next = m_head;
    4040    m_head = heap;
     
    4343IsoHeapImplBase* AllIsoHeaps::head()
    4444{
    45     std::lock_guard<Mutex> locker(m_lock);
     45    std::lock_guard<Mutex> locker(mutex());
    4646    return m_head;
    4747}
  • trunk/Source/bmalloc/bmalloc/AllIsoHeaps.h

    r242938 r244497  
    4343   
    4444private:
    45     Mutex m_lock;
    4645    IsoHeapImplBase* m_head { nullptr };
    4746};
  • trunk/Source/bmalloc/bmalloc/CryptoRandom.cpp

    r242938 r244497  
    7575    ARC4Stream m_stream;
    7676    int m_count;
    77     Mutex m_mutex;
    7877};
    7978DECLARE_STATIC_PER_PROCESS_STORAGE(ARC4RandomNumberGenerator);
     
    166165void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
    167166{
    168     std::lock_guard<Mutex> lock(m_mutex);
     167    std::lock_guard<Mutex> lock(mutex());
    169168
    170169    unsigned char* result = reinterpret_cast<unsigned char*>(buffer);
  • trunk/Source/bmalloc/bmalloc/DebugHeap.cpp

    r242938 r244497  
    150150        return nullptr;
    151151    {
    152         std::lock_guard<std::mutex> locker(m_lock);
     152        std::lock_guard<Mutex> locker(mutex());
    153153        m_sizeMap[result] = size;
    154154    }
     
    163163    size_t size;
    164164    {
    165         std::lock_guard<std::mutex> locker(m_lock);
     165        std::lock_guard<Mutex> locker(mutex());
    166166        size = m_sizeMap[base];
    167167        size_t numErased = m_sizeMap.erase(base);
  • trunk/Source/bmalloc/bmalloc/DebugHeap.h

    r242938 r244497  
    6262    // This is the debug heap. We can use whatever data structures we like. It doesn't matter.
    6363    size_t m_pageSize { 0 };
    64     std::mutex m_lock;
    6564    std::unordered_map<void*, size_t> m_sizeMap;
    6665};
  • trunk/Source/bmalloc/bmalloc/Scavenger.cpp

    r243165 r244497  
    8888void Scavenger::run()
    8989{
    90     std::lock_guard<Mutex> lock(m_mutex);
     90    std::lock_guard<Mutex> lock(mutex());
    9191    runHoldingLock();
    9292}
     
    100100void Scavenger::runSoon()
    101101{
    102     std::lock_guard<Mutex> lock(m_mutex);
     102    std::lock_guard<Mutex> lock(mutex());
    103103    runSoonHoldingLock();
    104104}
     
    120120void Scavenger::scheduleIfUnderMemoryPressure(size_t bytes)
    121121{
    122     std::lock_guard<Mutex> lock(m_mutex);
     122    std::lock_guard<Mutex> lock(mutex());
    123123    scheduleIfUnderMemoryPressureHoldingLock(bytes);
    124124}
     
    144144void Scavenger::schedule(size_t bytes)
    145145{
    146     std::lock_guard<Mutex> lock(m_mutex);
     146    std::lock_guard<Mutex> lock(mutex());
    147147    scheduleIfUnderMemoryPressureHoldingLock(bytes);
    148148   
     
    175175std::chrono::milliseconds Scavenger::timeSinceLastFullScavenge()
    176176{
    177     std::unique_lock<Mutex> lock(m_mutex);
     177    std::unique_lock<Mutex> lock(mutex());
    178178    return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_lastFullScavengeTime);
    179179}
     
    247247
    248248    {
    249         std::unique_lock<Mutex> lock(m_mutex);
     249        std::unique_lock<Mutex> lock(mutex());
    250250        m_lastFullScavengeTime = std::chrono::steady_clock::now();
    251251    }
     
    313313    while (true) {
    314314        if (m_state == State::Sleep) {
    315             std::unique_lock<Mutex> lock(m_mutex);
     315            std::unique_lock<Mutex> lock(mutex());
    316316            m_condition.wait(lock, [&]() { return m_state != State::Sleep; });
    317317        }
    318318       
    319319        if (m_state == State::RunSoon) {
    320             std::unique_lock<Mutex> lock(m_mutex);
     320            std::unique_lock<Mutex> lock(mutex());
    321321            m_condition.wait_for(lock, m_waitTime, [&]() { return m_state != State::RunSoon; });
    322322        }
  • trunk/Source/bmalloc/bmalloc/Scavenger.h

    r243144 r244497  
    9797    bool m_isInMiniMode { false };
    9898   
    99     Mutex m_mutex;
    10099    Mutex m_scavengingMutex;
    101100    std::condition_variable_any m_condition;
Note: See TracChangeset for help on using the changeset viewer.