Exemplo n.º 1
0
void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line)
{
    BASSERT(!line->refCount(lock));
    SmallPage* page = SmallPage::get(line);
    size_t refCount = page->refCount(lock);
    page->deref(lock);

    switch (refCount) {
    case SmallPage::lineCount: {
        // First free line in the page.
        m_smallPagesWithFreeLines[page->sizeClass()].push(page);
        break;
    }
    case 1: {
        // Last free line in the page.
        m_smallPages.push(page);
        m_scavenger.run();
        break;
    }
    }
}
Exemplo n.º 2
0
SmallPage* Heap::allocateSmallPage(std::lock_guard<StaticMutex>& lock, size_t sizeClass)
{
    Vector<SmallPage*>& smallPagesWithFreeLines = m_smallPagesWithFreeLines[sizeClass];
    while (smallPagesWithFreeLines.size()) {
        SmallPage* page = smallPagesWithFreeLines.pop();
        if (!page->refCount(lock) || page->sizeClass() != sizeClass) // Page was promoted to the pages list.
            continue;
        return page;
    }

    SmallPage* page = [this, sizeClass]() {
        if (m_smallPages.size())
            return m_smallPages.pop();

        m_isAllocatingPages = true;
        return m_vmHeap.allocateSmallPage();
    }();

    page->setSizeClass(sizeClass);
    return page;
}