Skip to content

Commit fe81aba

Browse files
committed
[JSC] Unify allocators
https://bugs.webkit.org/show_bug.cgi?id=323629 rdar://186860590 Reviewed by Marcus Plutowski. Previously each Subspace is having its own allocator. But this is wasteful so this patch unifies them into one. So we can unlock exchanging MarkedBlock between them. But we intentionally do not exchange MarkedBlock when it is destructible. This is because MarkedBlock::sweep becomes costly, and it puts sudden cost to the unrelated place when some non destructible cell uses MarkedBlock coming from destructible cell. * Source/JavaScriptCore/heap/BlockDirectory.cpp: (JSC::BlockDirectory::findEmptyBlockToSteal): * Source/JavaScriptCore/heap/IsoSubspace.cpp: (JSC::IsoSubspace::IsoSubspace): Canonical link: https://commits.webkit.org/320655@main
1 parent 18ee793 commit fe81aba

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Source/JavaScriptCore/heap/BlockDirectory.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ void BlockDirectory::updatePercentageOfPagedOutPages(SimpleStats& stats)
100100
MarkedBlock::Handle* BlockDirectory::findEmptyBlockToSteal()
101101
{
102102
Locker locker(bitvectorLock());
103-
m_emptyCursor = (emptyBits() & ~inUseBits()).findBit(m_emptyCursor, true);
103+
// A destructible block still owes its old owner a destructor pass over every cell, and whoever
104+
// takes the block has to pay it inline before the block can be re-typed. That costs about a
105+
// microsecond, far more than just asking the OS for a fresh block, so leave those blocks for the
106+
// sweeper and only trade ones that are already swept.
107+
m_emptyCursor = (emptyBits() & ~destructibleBits() & ~inUseBits()).findBit(m_emptyCursor, true);
104108
if (m_emptyCursor >= m_blocks.size())
105109
return nullptr;
106110
dataLogLnIf(BlockDirectoryInternal::verbose, "Setting block ", m_emptyCursor, " in use (findEmptyBlockToSteal) for ", *this);

Source/JavaScriptCore/heap/IsoSubspace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ WTF_MAKE_TZONE_ALLOCATED_IMPL(IsoSubspace);
3939
IsoSubspace::IsoSubspace(CString name, JSC::Heap& heap, const HeapCellType& heapCellType, size_t size, uint8_t numberOfLowerTierPreciseCells, std::unique_ptr<AlignedMemoryAllocator>&& allocator)
4040
: Subspace(SubspaceKind::IsoSubspace, name, heap)
4141
, m_directory(WTF::roundUpToMultipleOf<MarkedBlock::atomSize>(size))
42-
, m_allocator(allocator ? WTF::move(allocator) : makeUnique<FastMallocAlignedMemoryAllocator>())
42+
, m_allocator(WTF::move(allocator))
4343
{
4444
m_remainingLowerTierPreciseCount = numberOfLowerTierPreciseCells;
4545
ASSERT(WTF::roundUpToMultipleOf<MarkedBlock::atomSize>(size) == cellSize());
4646
ASSERT(m_remainingLowerTierPreciseCount <= MarkedBlock::maxNumberOfLowerTierPreciseCells);
4747

48-
initialize(heapCellType, m_allocator.get());
48+
initialize(heapCellType, m_allocator ? m_allocator.get() : heap.fastMallocAllocator.get());
4949

5050
Locker locker { m_space.directoryLock() };
5151
m_directory.setSubspace(this);

0 commit comments

Comments
 (0)