-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with mksnapshot and binding data #35930
Comments
(Fwiw, I know I’ve been pinged but I’ll unsubscribe because I’m not ready to deal with this ******** again. I’ve had working code that would have solved this, the project decided against it, not my problem anymore.) |
I had an alternative approach here, which implements the option2s in the pending discussions in the design doc. It was removed from #32984 since my intention was to land a minimal snapshot while keeping the options open to alternatives like the ones proposed by Anna (when the PR landed, there were no BaseObject before the pre-execution phase after refactoring anyway). I can rebase the patch and make it possible to add BaseObjects into the mksnapshot. BTW what are you planning to add in |
Just adding a link to the tracking issue, thanks for opening this one #35711 |
Just posting my WIP here after some trial and error (it's not working yet). I still think the best way to deal with C++ -> JS references (including references from BindingData to AliasedBuffers) should be solved by putting them behind private symbols at serialization time and restoring them back at deserialization time so that V8 does most of the graph-walking for us and it's less error-prone due to GC |
When looking into all the embedder objects, I realized that we never actually use
This should work for what we currently have, which is that BaseObjects all store at slot 0 a pointer to one C++ object which in turn reference other stuff, also at slot 1 or higher some more pointers. I will try to open a PR once my branch can handle slot 0, and leave other slots as TODO (which leaves out things like UDPWrap and StreamReq) |
Well..it looks like we can't just use the serialization callbacks for everything - because the |
Update: I changed the approach in the WIP a bit and stored a v8::String in the BaseObjects (only for serializable BaseObjects) so that at serialization time, we can identify the type of the object by looking at the string at slot 0. This may be useful for post-mortem debugging as well. For now, only the I also noticed that only a handful of BaseObjects seem to be eligible for serialization
It does not seem to make sense to serialize any of the AsyncWraps or the OpenSSL contexts - they should be gone after GC when we serialize the context (which is why we need to use the serialization callback since otherwise we can't avoid touching objects that aren't supposed in the snapshot), and if they have to be saved, some logic in JS should be done to make sure they are reinitialized properly after deserialization. |
hmm, I just realized that with the simplest two binding data (the fs one and the v8 one), there is no need to deserialize their AliasedBuffers at all since those are stats buffer and their content can be thrown away once consumed (which is guaranteed at snapshot time because by then no JS frame should be left on stack). I'll stash my WIP that support JS reference serialization on a different branch, and open a PR soon with a simplified approach (i.e. just re-initializing the aliased buffers, I think it's just much more straight forward than deserializing and the performance difference should be negligible) |
PR-URL: #36943 Fixes: #35930 Refs: #35711 Reviewed-By: James M Snell <[email protected]>
PR-URL: #36943 Fixes: #35930 Refs: #35711 Reviewed-By: James M Snell <[email protected]>
This patch adds the SnapshotableObject interface. Native objects supporting serialization can inherit from it, implementing PrepareForSerialization(), Serialize() and Deserialize() to control how the native states should be serialized and deserialized. See doc: https://docs.google.com/document/d/15bu038I36oILq5t4Qju1sS2nKudVB6NSGWz00oD48Q8/edit PR-URL: #36943 Fixes: #35930 Refs: #35711 Reviewed-By: James M Snell <[email protected]>
PR-URL: #36943 Fixes: #35930 Refs: #35711 Reviewed-By: James M Snell <[email protected]>
PR-URL: #36943 Fixes: #35930 Refs: #35711 Reviewed-By: James M Snell <[email protected]>
@joyeecheung ... I'm running into an issue with the node_mksnapshot tool during build. It apparently does not know how to handle BindingData for native modules when the snapshot is created...
I'm working on a rework of
internalBinding('trace_events')
module, and attempting to add binding data to it:The
trace_events
module is loaded during bootstrap, so the createdTraceEventsState
object is attached as the binding data at that step.Unfortunately, this causes
node_mksnapshot
to crash:We should be able to attach
BindingData
to any of the internal native modules without having to fight with this. I know that addaleax's original implementation design for this bit covered but I'm not sure of the details so I'm not entirely sure what is missing in the version of your approach that landed here.The text was updated successfully, but these errors were encountered: