Skip to content
Permalink
Browse files
[JSC] Adjust ArrayBuffer size tracking only when full GC happens
https://bugs.webkit.org/show_bug.cgi?id=242630
rdar://problem/96850434

Reviewed by Mark Lam.

This patch fixes it so that we adjust ArrayBuffer size tracking only when full GC happens.
This is because right now our GC expects that Eden GC only collects newly allocated Eden memory.
And it is not expecting that we can reduce extra-memory. We can enhance it in the future, but for now,
only adjust it at full GC time

* Source/JavaScriptCore/heap/GCIncomingRefCountedSet.h:
* Source/JavaScriptCore/heap/GCIncomingRefCountedSetInlines.h:
(JSC::GCIncomingRefCountedSet<T>::sweep):
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::sweepArrayBuffers):

Canonical link: https://commits.webkit.org/252368@main
  • Loading branch information
Constellation committed Jul 12, 2022
1 parent d5d5622 commit 8136ad12111fb4e589c0aa38201f1f30601f7e15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
@@ -41,7 +41,7 @@ class GCIncomingRefCountedSet {
// Returns true if the native object is new to this set.
bool addReference(JSCell*, T*);

void sweep(VM&);
void sweep(VM&, CollectionScope);

size_t size() const { return m_bytes; };

@@ -59,19 +59,22 @@ bool GCIncomingRefCountedSet<T>::addReference(JSCell* cell, T* object)
}

template<typename T>
void GCIncomingRefCountedSet<T>::sweep(VM& vm)
void GCIncomingRefCountedSet<T>::sweep(VM& vm, CollectionScope collectionScope)
{
m_bytes = 0;
size_t preciseBytes = 0;
m_vector.removeAllMatching([&](T* object) {
size_t size = object->gcSizeEstimateInBytes();
ASSERT(object->isDeferred());
ASSERT(object->numberOfIncomingReferences());
if (!object->filterIncomingReferences([&] (JSCell* cell) { return vm.heap.isMarked(cell); })) {
m_bytes += size;
preciseBytes += size;
return false;
}
return true;
});
// Update m_bytes to the precise value when Full-GC happens since Eden-GC only expects that Eden region is collected.
if (collectionScope == CollectionScope::Full)
m_bytes = preciseBytes;
}

} // namespace JSC
@@ -2282,7 +2282,7 @@ void Heap::pruneStaleEntriesFromWeakGCHashTables()

void Heap::sweepArrayBuffers()
{
m_arrayBuffers.sweep(vm());
m_arrayBuffers.sweep(vm(), collectionScope().value_or(CollectionScope::Eden));
}

void Heap::snapshotUnswept()

0 comments on commit 8136ad1

Please sign in to comment.