GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Describe node's deferred finalization from V8's GC poll by Andarist · Pull Request #197 · replayio/node Conversation
Member
replay-node polled for what the GC collected three times per microtask checkpoint: V8's ReplayGCPoll (WeakRefs, FinalizationRegistries), DeferredFinalization's own microtasks-completed callback, and one per napi_env for cleared N-API references. Each recorded its own value, in an order that depended on callback registration. V8's poll now takes embedder participants The N-API checkpoint flush is gone. The only reader of a reference's value, napi_get_reference_value, flushes the cleared references itself, and a collected tracked reference is finalized at the next GC poll on both sides, which resets its handle. Ids of finalized or deleted references are dropped from the recording-side set, so it no longer grows without reads. The recording format changes: node's values come after V8's in each poll, and DeferredFinalization.poll is only recorded when GC.poll says so.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsreplay-node polled for what the GC collected three times per microtask checkpoint: V8's ReplayGCPoll (WeakRefs, FinalizationRegistries), DeferredFinalization's own microtasks-completed callback, and one per napi_env for cleared N-API references. Each recorded its own value, in an order that depended on callback registration. V8's poll now takes embedder participants (v8::replayio::ReplayGCPollParticipant, synced from replayio/chromium-v8): it records one "GC.poll" value per poll, with a bit saying whether an active participant has something pending, and then calls the participants in the order they were added. DeferredFinalization is such a participant instead of registering its own callback. The N-API checkpoint flush is gone. The only reader of a reference's value, napi_get_reference_value, flushes the cleared references itself, and a collected tracked reference is finalized at the next GC poll on both sides, which resets its handle. Ids of finalized or deleted references are dropped from the recording-side set, so it no longer grows without reads. The recording format changes: node's values come after V8's in each poll, and DeferredFinalization.poll is only recorded when GC.poll says so. Co-Authored-By: Claude Fable 5.1 <[email protected]> The poll also runs when the embedder calls Isolate::ClearKeptObjects(), which is how node reaches it when a callback scope closes, and an active participant makes it record as a tracked WeakRef or registration does. Co-Authored-By: Claude Fable 5.1 <[email protected]> Uh oh!
There was an error while loading. Please reload this page.
bhackett1024
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
bhackett1024
pushed a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Add recordreplay::DeferredFinalization, owned by the Environment and added to V8's GC poll as a participant: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Add recordreplay::DeferredFinalization, owned by the Environment and added to V8's GC poll as a participant: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Add recordreplay::DeferredFinalization, owned by the Environment and added to V8's GC poll as a participant: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Add recordreplay::DeferredFinalization, owned by the Environment and added to V8's GC poll as a participant: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Add recordreplay::DeferredFinalization, owned by the Environment and added to V8's GC poll as a participant: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. A module which registered with NAPI_VERSION_EXPERIMENTAL still gets its finalizer inline, which is what node does for it as well. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. A module which registered with NAPI_VERSION_EXPERIMENTAL still gets its finalizer inline, which is what node does for it as well. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
pushed a commit
that referenced
this pull request
Patch native addon registration for recording/replaying, add pointer registration for addon handles, and serialize module content for deterministic addon loading. Mark an addon's dlopen() for the driver with the addon's name, so the driver attaches the addon wherever it is loaded from instead of only under node_modules. Record/replay whether a weak N-API reference's value is still alive. A module reading one with napi_get_reference_value gets its value or, once the GC collected it, nothing, and the GC runs at other points when replaying, so the module could see a value the recording didn't or the other way around. References the module creates in calls the driver replays (RecordReplayIsInsideInterceptedCallback says which those are) get an id and have their values held strongly when replaying; the ids of references whose values the GC collected are recorded whenever the module reads a reference, and the replay clears exactly those references then. A collected reference's finalizer, and its deletion when it deletes itself, are deferred to the next GC poll on both sides through node's deferred finalization, with a stub standing in for a finalizer the replayed call was not given, since module finalizers never run when replaying. A module's finalizer is module code, which node does not run from the GC: it hands it to the environment's second pass, an immediate (napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there too rather than calling Finalize() itself, so that a finalizer never runs nested inside whatever the module was doing when the poll was reached -- its own napi_make_callback, say -- which never happens without the recorder. Reaching that deferral from the GC is what a tracked reference cannot do, since the GC runs at points which differ between recording and replaying; reaching it from the poll is the same point on both sides. Node 20 splits Reference::New into Reference, ReferenceWithData and ReferenceWithFinalizer factories, and the references with finalizers are exactly the latter two, so each factory tracks its reference rather than the base one alone; the record/replay bookkeeping carries its own env and asks the subclass that owns the finalizer about it, since node 20 keeps both off Reference. Nothing tracked means nothing deferred to a GC poll, and napi-add-finalizer-collected and napi-external-finalizers-collected then see no finalizations at all, because without the deferral they only run at environment teardown. Node 24 splits the reference classes further, so the record/replay tracking follows its factories rather than a single New(). Rebase note: native addon code does not run when replaying. The addon's node_module struct is restored from the recording, and the exports value returned by its init function is mapped back through RegisterPointer/PointerId. Any new upstream path that calls an addon's register/init function needs the same treatment or must invalidate the recording, as the legacy nm_register_func path does. Everything a module can observe about the GC's timing (whether a weak reference still has a value, when a finalizer runs) has to be recorded and replayed at fixed points instead of being left to the replay's own GC. Includes later changes from #167, #168, #171 and #197. Co-authored-by: Mateusz Burzyński <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist
added a commit
that referenced
this pull request
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |