Closed Bug 1731121 Opened 3 years ago Closed 3 years ago

Collect type definitions referenced by wasm-GC objects


(Core :: JavaScript: WebAssembly, task, P3)




94 Branch
Tracking Status
firefox94 --- fixed


(Reporter: rhunt, Assigned: rhunt)




(6 files)

Currently we allocate GC type definitions in a JSContext global TypeContext per instantiation. Then when we allocate GC objects for that instance, we use an index into the JSContext global TypeContext for the RttValue. This scheme is easy to implement but doesn't allow the type definitions to ever be freed.

Driveby fix to use a more descriptive 'subtype' 'supertype' naming
scheme for the subtype algorithm and tests. Equivalence testing
is changed to first/second as well.

This commit makes TypeContext refcounted/shareable. This is so that
we can change RttValue's representation to be:

  1. RefPtr<TypeContext> typeContext;
  2. uint32_t typeIndex;
    Effectively adding an explicit type context field to RttValue instead
    of using an implicit global TypeContext, as it is now.

The big change here is that as TypeContext is now refcounted, it
needs to be heap-allocated, and cannot be a plain member of
ModuleEnvironment, as it is now. This adds some extra indirections.
If this is unacceptable, then I think we can find a workaround.

The next commit will implement the changes to RttValue.

Depends on D125888

Drop the global type context from WasmContext. RttValue's now hold
a strong reference to their TypeContext which they can use with their
pre-existing type index to get their type definition.

Depends on D125889

RttValue::Size,Kind were required when a JSContext* was needed to
access the TypeDef object. This is no longer a requirement and so we
can just directly get those fields.

Depends on D125890

While we're at it, let's remove the TypedProto slot as well. This is
currently unused and unlikely to match whatever is decided upon for

Depends on D125891

The direct pointer to TypeDef* is needed far more often, and can be used to
map back to the index whenever required.

Depends on D125892

Pushed by
wasm: Use better names in subtype algorithms. r=lth
wasm: Make TypeContext refcounted and shareable. r=lth
wasm: Drop implicit global type context and refer to explicit TypeContext in RttValue. r=lth
wasm: Drop duplicated slots no longer needed. r=lth
wasm: Drop TypedProto. r=lth
wasm: Store raw pointer to TypeDef instead of index in RttValue. r=lth
Regressions: 1731599
You need to log in before you can comment on or make changes to this bug.