Make __instance_signal and __instance_terminated fully indepedent #6270
Make __instance_signal and __instance_terminated fully indepedent #6270logan-gatlin wants to merge 3 commits intomainfrom
Conversation
Co-authored-by: logan-gatlin <[email protected]>
|
The old code had I've done a thorough review of all the changes. The code is well-structured, safe, and properly tested. I don't see any actionable issues — no logic bugs, no safety issues, no missing compat flags (since it's gated by an existing autogate), and no backward compatibility concerns. LGTM |
Merging this PR will degrade performance by 19.65%
Performance Changes
Comparing Footnotes
|
Currently, __instance_signal is ignored if __instance_terminated is not present. This is because registering a signal creates a strong reference to the instance's memory, and we need some indication of when it is safe to free it. Keeping a weak reference to the memory is not an option, since weak references are not safe to use in a signal handler.
The new solution is to keep a weak reference to the instance alongside our strong reference to its memory. Then in the GC prologue, in addition to freeing memories that have __instance_terminated set, we will also free memories where our instance weakref is now dead. I have confirmed through tests and by looking at V8 src code that a WASM memory does not keep the instance it is attached to alive