Open Bug 1993212 Opened 3 months ago Updated 4 days ago

Investigate allocating WeakMap memory with the buffer allocator

Categories

(Core :: JavaScript: GC, task, P2)

task

Tracking

()

People

(Reporter: jonco, Assigned: jonco)

References

(Blocks 2 open bugs)

Details

Attachments

(10 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

This should make things more efficient.

Severity: -- → N/A
Priority: -- → P2
Blocks: 1983485

According to mfbt/AllocPolicy.h, allocation policies are supposed to implement
a 'reportAllocOverflow' method. This is used both by the implmementation of the
alloc policy itself and also by containers such as mfbt/HashTable.h when
growing its table.

Our MallocProvider mixin class implements most of the AllocPolicy methods for
a client class, but requires clients to provide a 'reportAllocationOverflow'
method.

Thus clients must provide both methods if they want to be used by containers.
Currently only TrackedAllocPolicy (a.k.a. ZoneAllocPolicy) does this, by having
reportAllocOverflow call reportAllocationOverflow.

The current situation is confusing. We can simplify this by making
MallocProvider use the reportAllocOverflow name and renaming to this
everywhere.

This refactoring gives us a place to put default method definitions without
adding them to every policy.

The patch also renames some alloc policy classes to make it clear they use malloc allocation.

This makes handling OOM simpler in the next patch because we don't need to
retry at a higher level.

To support using GC memory in containers we need a way to trace that memory.
This patch adds a 'getExternalAllocPtr' method to vector and hash table containers
that can be used to get the pointer to trace.

The patch adds BufferAllocPolicy which allocates memory using the buffer
allocator and provides a traceExternalAlloc method to trace the allocations, as
well as updating its knowledge of whether the owning cell is tenured.

Previously calls to the buffer allocator to allocate/free memory were always
done from the main thread and so no locking was required. GC sweeping can be
split between more than one helper thread so we need a way to make this thread
safe.

The patch adds a way to set up debug build assertions in the buffer allocator
by passing a mutex that the caller must hold. The caller is responsible for
actually taking/releasing the lock.

This sets up multi-threaded use of the buffer allocator during sweep slices
using an existing mutex. While sweeping weak maps the mutex is only held when
destroying the weak map iterator as this is the part that may resize the table
and hence call into the allocator. This is also the part required by existing
use of the lock for weak map sweeping.

Since this mutex is now used for more than synchronizing access to the store
buffer it is renamed to the sweeping lock.

Currently the memOf parameter is optional for both constructors. This patch
changes it so that for a weak map with an owning JSObject you need to pass
context and owning object, and for non-owned ones you only pass the zone.

Finally we can switch over to using the buffer allocator for weak maps, both
the WeakMap allocation and the hash table memory via BufferAllocPolicy.

WeakMap objects remain tenured. I haven't thought about whether it's worth
trying to nursery allocate these.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: