GC runtime instance lifetimes #567
Replies: 1 comment 1 reply
-
A typical runtime won't reified store objects. Rather, the execution stack is generally the source of all roots, and activation frames contain the locals and operand stack. Typically at the implementation level there is an additional reference to an object that represents an instance, and the instance has references to tables and globals. Thus if you consider the execution stack to be the source of all roots and trace through instances, then there is no need to consider some references to be weak. Often, an optimizing compiler may shorten the lifetimes of locals and even operand slots, so it's possible that even locals do not represent real roots. Since Wasm GC currently has no way to observe collection of objects, it's an unobservable optimization to collect objects early. |
Beta Was this translation helpful? Give feedback.
-
Struct and Array Instances are allocated in the Store, the stores reference to the instances prevents these objects from being GC'd until the store itself is deallocated (In my particular runtime impl). As an optimisation I store a strong reference to the struct instance hidden in the execution value and make the reference to the struct instance in the store a weak reference. The idea being that as soon as the execution value is popped from the stack (or is mutated out from a global) then the GC will be able to reclaim the structs/array.
Is there any guidance around this as I'm not sure if I'm violating an invariant by having some of the stores state reclaimed early? Would be interested to know how others tackled it?
Beta Was this translation helpful? Give feedback.
All reactions