Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 94bf250671379cc3588afbabe460c85d640101fc
https://github.com/WebKit/WebKit/commit/94bf250671379cc3588afbabe460c85d640101fc
Author: Dan Hecht <[email protected]>
Date: 2026-10-13 (Tue, 13 Oct 2026)
Changed paths:
A JSTests/stress/heap-size-counts-live-memory.js
M Source/JavaScriptCore/heap/AbstractSlotVisitorInlines.h
M Source/JavaScriptCore/heap/Collector.cpp
M Source/JavaScriptCore/heap/Collector.h
M Source/JavaScriptCore/heap/Heap.cpp
M Source/JavaScriptCore/heap/Heap.h
M Source/JavaScriptCore/heap/SlotVisitor.cpp
M Source/JavaScriptCore/heap/SlotVisitor.h
M Source/JavaScriptCore/heap/SlotVisitorInlines.h
Log Message:
-----------
[JSC] Make the GC's memory accounting work for collections of several heaps
https://bugs.webkit.org/show_bug.cgi?id=327301
rdar://189847525
Reviewed by Yusuke Suzuki.
A heap's size and allocation limits come from the bytes the visitors mark in
it and the extra memory its cells report while being visited. The visitors
counted both for the whole collection and charged them to the Collector's first
heap. Each count now goes to the heap it belongs to.
Bytes visited: a visitor counts the bytes it marks for the heap it marked most
recently, and adds that count to the heap's own counter when it marks another
heap's cell, which will be rare since a heap's cells will mostly reference
their own heap's cells, and at the end of marking. Each heap's endMarking()
reads its own counter, instead of the Collector handing every heap the
collection's total. The counter takes the place of
m_totalBytesVisitedThisCycle, which was written but never read, so Heap's
layout is unchanged. Note that marking has just read the marking version from
the block's header and updated its mark count, and the VM pointer is on the
same cache line.
Extra memory: a report is charged to the heap of the cell being visited, which
is the cell reporting it. Its block header may no longer be in cache by the
time the cell is visited, but reports are far rarer than marks. The visitor
still accumulates extra memory for one heap at a time, flushing it to that heap
at the end of each drain batch, and now also when a report comes from another
heap's cell. External memory goes straight to the reporting cell's heap.
The visitors flush both counts at the end of marking, and reset() checks that
nothing is left. That leaves nothing for SlotVisitor::didStartMarking to do per
collection scope: the Eden reset() repeated the one at the end of every
collection, and the Full collection's zeroing of the extra memory count was a
no-op. didStartMarking now asserts the visitor is clean instead.
Test: JSTests/stress/heap-size-counts-live-memory.js
* JSTests/stress/heap-size-counts-live-memory.js: Added.
(shouldBeAtLeast):
(measure):
(shouldHaveGrownBy):
* Source/JavaScriptCore/heap/AbstractSlotVisitorInlines.h:
(JSC::AbstractSlotVisitor::didStartMarking):
* Source/JavaScriptCore/heap/Collector.cpp:
(JSC::Collector::runEndPhase):
(JSC::Collector::endCollectionInEachHeap):
(JSC::Collector::bytesVisitedIn): Deleted.
* Source/JavaScriptCore/heap/Collector.h:
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::beginMarking):
(JSC::Heap::recordBytesVisited):
(JSC::Heap::endMarking):
* Source/JavaScriptCore/heap/Heap.h:
(JSC::Heap::reportBytesVisited):
* Source/JavaScriptCore/heap/SlotVisitor.cpp:
(JSC::SlotVisitor::didStartMarking):
(JSC::SlotVisitor::reset):
(JSC::SlotVisitor::appendToMarkStack):
(JSC::SlotVisitor::noteLiveAuxiliaryCell):
(JSC::SlotVisitor::noteBytesVisited):
(JSC::SlotVisitor::flushBytesVisited):
(JSC::SlotVisitor::propagateExternalMemoryVisitedIfNecessary):
(JSC::SlotVisitor::flushExtraMemoryVisited):
* Source/JavaScriptCore/heap/SlotVisitor.h:
* Source/JavaScriptCore/heap/SlotVisitorInlines.h:
(JSC::SlotVisitor::reportExtraMemoryVisited):
(JSC::SlotVisitor::reportExternalMemoryVisited):
Canonical link: https://commits.webkit.org/323597@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications