Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ class WarmUpBlockProvider {
return Options::useWarmUpMarkedBlocks() && Options::warmUpMarkedBlockCount() && !VM::isInMiniMode();
}

// Bringing up a VM takes a few dozen blocks, and a short program never asks for many more; for
// it the helper thread is only a thread to create, fault a supply on and tear down again at exit.
// So the provider stays dormant until the process has requested this many blocks. A heap that
// is ramping passes the threshold within its first milliseconds of allocation, and the helper
// then fills the supply to its full depth as it would have from the first request.
static bool isPastStartThreshold()
{
static std::atomic<bool> past { false };
static std::atomic<unsigned> requests { 0 };
if (past.load(std::memory_order_relaxed)) [[likely]]
return true;
if (requests.fetch_add(1, std::memory_order_relaxed) + 1 < Options::warmUpMarkedBlockStartAfterBlocks())
return false;
past.store(true, std::memory_order_relaxed);
return true;
}

static WarmUpBlockProvider& singleton()
{
static LazyNeverDestroyed<WarmUpBlockProvider> provider;
Expand Down Expand Up @@ -278,7 +261,7 @@ void* FastMallocAlignedMemoryAllocator::tryAllocateAlignedMemory(size_t alignmen
#else
// MarkedBlock::tryCreate is the only caller today and always asks for a block-shaped region.
// The guard keeps a future caller of some other size from being handed a block.
if (alignment == MarkedBlock::blockSize && size == MarkedBlock::blockSize && WarmUpBlockProvider::isEnabled() && WarmUpBlockProvider::isPastStartThreshold()) {
if (alignment == MarkedBlock::blockSize && size == MarkedBlock::blockSize && WarmUpBlockProvider::isEnabled()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 Pre-existing: this revert moves the first helper-thread spawn back to VM bring-up, but Thread::create is still issued from tryAllocateAlignedMemory on the mutator every time the helper has idle-timed-out (10 s of no block requests) and a new block is needed, so a long-running profiled process on Windows can still hit the same sampler self-deadlock the PR is reverting to avoid. Fix: never spawn the helper from the allocator — restart it from a safepoint, or drop the idle timeout so the OS thread stays alive once created.

Extended reasoning...

After the supply is filled and block demand stops, AutomaticThread waits warmUpMarkedBlockIdleTimeout (default 10 s), WarmUpThread::shouldSleep() sees m_demandSinceIdleCheck clear, and the OS thread exits via stopForTimeout → threadIsStopping (m_hasUnderlyingThread=false, m_phase=Stopped, m_blocks freed). The next MarkedBlock request reaches line 264 → singleton().tryTake() finds the supply empty and phase≠StandingDown → m_condition->notifyOne() → AutomaticThreadCondition::notifyOne finds !hasUnderlyingThread() → AutomaticThread::start() → WTF::Thread::create(), all on the JS mutator inside the allocation slow path with user code on the stack. That is the exact call the PR description names as the Windows self-deadlock trigger when SamplingProfiler suspends the JS thread mid thread-creation. The base branch has this same restart path (plus the 64th-block path the revert removes), so this is an unfixed sibling of the bug being addressed rather than a regression; a steady-state heap easily goes 10 s without needing a fresh MarkedBlock, so the window is…

Verification: pre-existing — the idle-timeout restart path is untouched by this diff and exists identically on the base branch (and pre-#553), so merging makes nothing worse; the specific CI test the PR targets completes in well under 10 s and won't hit it. Mechanism verified: - FastMallocAlignedMemoryAllocator.cpp:123 — WarmUpThread is constructed with timeout… | pre-existing — the idle-timeout re-spawn path…

if (void* block = WarmUpBlockProvider::singleton().tryTake())
return block;
}
Expand Down
1 change: 0 additions & 1 deletion Source/JavaScriptCore/runtime/OptionsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ bool hasCapacityToUseLargeGigacage();
v(Double, gcIncrementScale, 0, Normal, nullptr) \
v(Bool, useWarmUpMarkedBlocks, true, Normal, "hand MarkedBlock allocation pages that a helper thread already made resident"_s) \
v(Unsigned, warmUpMarkedBlockCount, 32, Normal, "how many MarkedBlocks the helper thread keeps ready with their pages already resident; 0 turns it off"_s) \
v(Unsigned, warmUpMarkedBlockStartAfterBlocks, 64, Normal, "how many MarkedBlocks the process allocates before the helper thread starts; a program that stops before that never creates it"_s) \
v(Double, warmUpMarkedBlockIdleTimeout, 10, Normal, "seconds without a MarkedBlock request before the helper thread releases what it is holding and shuts down"_s) \
v(Bool, scribbleFreeCells, false, Normal, nullptr) \
v(Bool, decommitUnusedMarkedBlockPages, true, Normal, "after sweeping a MarkedBlock, return its interior OS pages that hold no live cell to the OS (only where OS pages are smaller than a MarkedBlock)") \
Expand Down
Loading