-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
src: track cppgc wrappers with CppgcWrapperList in Environment #56534
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56534 +/- ##
==========================================
- Coverage 89.12% 89.06% -0.07%
==========================================
Files 662 662
Lines 191556 191670 +114
Branches 36860 36813 -47
==========================================
- Hits 170732 170705 -27
- Misses 13690 13808 +118
- Partials 7134 7157 +23
|
src/README.md
Outdated
the `Environment` is already gone, it must implement the cleanup with this pattern: | ||
|
||
```c++ | ||
~MyWrap() { this->Clean(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumptions should not be made about the order and the timing of their execution. There is no guarantee on the order in which the destructors are invoked. That's why destructors must not access any other on-heap objects (which might have already been destructed). If some destructor unavoidably needs to access other on-heap objects, it will have to be converted to a pre-finalizer. The pre-finalizer is allowed to access other on-heap objects.
https://github.com/v8/v8/tree/main/include/cppgc#sweeping-phase
This example should depend on CPPGC_USING_PRE_FINALIZER
as it may access other heap objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to mention CPPGC_USING_PRE_FINALIZER
, though I noticed two things:
ContextifyContext
does not even need to have special cleanup and can just have a default destructor - when the destructors are invoked, the context is already going away as it would've been holding the ContextifyContext alive. So there's no need to set the internal pointers of the context; On the other hand since the context is already going away, the per-environment context list would now contain empty global handles to that context, and the context tracking code is already able to deal with empty handles, so it matters little to purge it from the list in the destructor (we could also do the housekeeping in the constructor, inTrackContext()
instead, to make sure there aren't too many empty handles lying around).- It seems the use of
CPPGC_USING_PRE_FINALIZER
would crash the construction ofContextifyContext
, which I have not gotten to the bottom of yet.
This allows us to perform cleanups of cppgc wrappers that rely on a living Environment during Environment shutdown. Otherwise the cleanup may happen during object destruction, which can be triggered by GC after Enivronment shutdown, leading to invalid access to Environment. The general pattern for this type of non-trivial destruction is designed to be: ``` class MyWrap final : CPPGC_MIXIN(MyWrap) { public: ~MyWrap() { this->Clean(); } void CleanEnvResource(Environment* env) override { // Do cleanup that relies on a living Environemnt. This // would be called by CppgcMixin::Clean() first during // Environment shutdown, while the Environment is still // alive. If the destructor calls Clean() again later // during garbage collection that happens after // Environment shutdown, CleanEnvResource() would be // skipped, preventing invalid access to the Environment. } } ``` In addition, this allows us to iterate over the wrappers to trace external memory held by the wrappers in the heap snapshots if we add synthethic edges between the wrappers and other nodes in the embdder graph callback, or to perform snapshot serialization for them.
37e7bac
to
195a9a4
Compare
This allows us to perform cleanups of cppgc wrappers that rely on a living Environment during Environment shutdown. Otherwise the cleanup may happen during object destruction, which can be triggered by GC after Enivronment shutdown, leading to invalid access to Environment.
The general pattern for this type of non-trivial destruction is designed to be:
In addition, this allows us to trace external memory held by the wrappers in the heap snapshots if we add synthethic edges between the wrappers and other nodes in the embdder graph callback, or to perform snapshot serialization for them.