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 — Finalize what the GC collects at deterministic points when recording/replaying by Andarist · Pull Request #171 · replayio/node Conversation
Member
Fourth PR of the old-space-GC stack, on top of #161. Old space GCs now run while recording, at points the replay does not reproduce, and which embedder objects die in one differs between the two. Cleanup that ran from a weak callback was therefore dropped or leaked until teardown: This replaces the per-site "leak it under record/replay" gates with one mechanism, Commits, each with a case on backend branch
Not changed: Verified locally against a local recorder build: the gc, native-modules and async-hooks groups pass (37 files), with record/replay agreement on every logged result.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Andarist
force-pushed
the
claude/gc-deferred-finalization
branch
from
62331c0 to
213e143
Compare
Andarist
force-pushed
the
claude/gc-deferred-finalization
branch
from
213e143 to
25bf666
Compare
Andarist
force-pushed
the
claude/gc-deferred-finalization
branch
from
25bf666 to
1ed5a7f
Compare
Domiii
approved these changes
When recording/replaying, a destroy which comes from the GC (a weak callback, or a wrap deleted by one) was dropped, since it happens at a point the replay does not reproduce. async_hooks destroy hooks never fired for collected resources, so domain's pairing map and userland per-async-id maps grew for the life of the process. Add recordreplay::DeferredFinalization, owned by the Environment: the weak callback only notes the id, and a microtasks-completed callback records the noted ids and emits the destroys from there, like V8's WeakRef/FinalizationRegistry handling (deps/v8/src/replay/gc-poll.cc) and the N-API reference poll. When replaying, the recorded ids are emitted at the same checkpoint and the replay's own GC destroys are dropped. The "deferred-finalization" feature switches this off, which leaves the destroys dropped as before. Co-Authored-By: Claude Fable 5.1 <[email protected]> …oint An open FileHandle or DirHandle the GC collected was leaked while recording/replaying (EnterLeakMemory), since closing it schedules a process warning, JS the replay could not run at the same point. Its fd stayed open until the environment was torn down. Extend recordreplay::DeferredFinalization to BaseObjects: a subclass calls RecordReplayTrack() before MakeWeak(), which gives the object an id when it is created at a deterministic point. When recording, the weak callback then only notes the id and the next poll runs OnGCCollect(); when replaying, MakeWeak() keeps the JS object alive and the poll runs OnGCCollect() where the recording did, so the fd is closed and the warning scheduled at the same point on both sides. An object created where no id could be assigned keeps the previous handling, with its LeakMemory diagnostic. FileHandle and DirHandle are the first users. Co-Authored-By: Claude Fable 5.1 <[email protected]> …eterministic point A collected N-API reference was left unfinalized until environment teardown when recording/replaying (never on process.exit()), so the native object behind every napi_wrap and napi_create_external leaked, and external Buffer data with a free callback (Buffer::New with a callback, napi_create_external_buffer) was leaked outright. Generalize recordreplay::DeferredFinalization from BaseObjects to a Finalizable interface, and make v8impl::Reference and Buffer::CallbackInfo users: the second pass callback, or the backing store's deleter (which runs on the sweeper's thread), only notes the id, and the poll finalizes the reference or runs the free callback at the next microtask checkpoint on both sides. When replaying, a tracked reference's value and a tracked Buffer's ArrayBuffer are kept alive until then. A reference or buffer created where no id could be assigned keeps the previous handling, with a LeakMemory diagnostic. Module finalizers run from an immediate scheduled at that point, so node_napi_env__::CallFinalizer and the external Buffer finalizer now call them inside a callback region, like a module's init: the N-API calls a finalizer makes are recorded and replayed at the same point, and the finalizer itself does not run when replaying. The replayed call that created the reference or buffer may have no finalizer (the driver passes it as null), so whether the recording had one is recorded and a stub stands in for it when replaying. Co-Authored-By: Claude Fable 5.1 <[email protected]> …ed IntervalHistograms at a deterministic point HandleWrap::OnGCCollect leaked every wrap when recording/replaying, including the closed wraps it is reached for from OnClose(), a path which replays: each closed TCP, UDP, pipe or timer handle kept its C++ wrap and, through the wrap's strong handle, its JS object for the life of the process. Delete closed wraps as upstream does; destroying them has no effect beyond freeing memory. An open wrap the GC collects (a weak one, e.g. IntervalHistogram) is closed from DeferredFinalization::Poll when tracked, and still leaked when it was created where no id could be assigned. IntervalHistogram tracks itself, which replaces holding it strongly when replaying: a tracked histogram is held until the recording shows the GC collected it, and an untracked one as before. Co-Authored-By: Claude Fable 5.1 <[email protected]> RecordReplayInvokeApiInterruptCallbacksAtProgress took the ordered lock once per queued entry, so the number of recorded lock rounds depended on the queue's contents. An entry queued by code which only runs when recording, a binary module calling v8::Isolate::RequestInterrupt (profilers, APM agents, the @replayio/v8-test-hooks test module), exists only in the recording's queue: the recording drained one more round than the replay, the recorded lock order diverged, and the replay failed with a linker mismatch. Swap the queue out under one lock round and run the entries outside it. The lock still orders pushes from other threads against the drain, and an entry a callback queues waits for the next trigger on both sides, which resetting record_replay_api_interrupt_triggered_ before the drain already arranges. Backed by the node-recording case v8/api-interrupts-at-progress, now on the test hooks instead of %ScheduleGCInStackCheck(). Same change to be made in the Chromium V8 fork, where the drain is identical. Co-Authored-By: Claude Fable 5.1 <[email protected]> What the record/replay bookkeeping needs is a point whose behaviour is semantically deterministic between recording and replay, where the same state is reached and the same decisions are made, so that a value recorded or cleanup run there reproduces. "A point which replays" named it badly: GC points replay too, at other places. Comments and diagnostics only. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Andarist
force-pushed
the
claude/gc-deferred-finalization
branch
from
1ed5a7f to
efd9451
Compare
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. 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. 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
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. 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
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
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]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh 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. |