-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[vm/ffi] KeepAlive
marker interface
#56227
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
Comments
@mkustermann: name option |
(I misremembered how this works in today's meeting) The current setup is:
I think the main reasons we currently disallow
So marking a class as
Eventually (with shared multi threading) we want a finalizer API that works across isolates (just like our existing C API works across isolates). So one way would be to have
But this may require two different marker interfaces or otherwise leaves room for user bugs where objects that are isolate-local are shared. We could go instead the other direction:
=> This would effectively align the So the main question is: Do we really care about early reclamation of isolate-local resources on unexpected isolate shutdown? This is only important if isolates are short lived and native resources aren't eagerly freed up by user code (or e.g. isolates get often killed) and we cannot wait for the GC to eventually run them a bit later. /cc @mraleph wdyt? (**) This assumption only makes sense for synchronous code. In asynchronous code one can easily have foo() async {
final obj = Foo(field);
finalizer.attach(foo, ...., () => ...);
final field = obj.field;
await <...>
// ^^^^
// - takes long time
// - may cause GC
// - may collect `obj` (as it's not used anymore & it's not `Finalizable)
// - GC may enqueue finalizer,
// - may run finalizer
useField(field); // <-- use field after finalizer has run
} |
That's not entirely true, canceling finalizers from another isolate doesn't work, from a previous discussion of ours:
I don't know of any such use cases. So, I like the idea of trying to make I believe we could make the existing |
The code may not care about detachment at all, it may only detach on the main isolate anyway, helper isolates could ask main isolate to detach or it may (in future) use
Wouldn't it throw a nice exception: "You cannot detach object
Making What is necessary is committing to the semantic changes of |
Right, if you cannot send the ➕ For changing
It does not. #56632 |
We currently have a
Finalizable
interface that serves two purposes:NativeFinalizer
s attached.Due to (2), we disallow sending objects implementing
Finalizable
to other isolates. As that that will most likely be an error.However, when attaching finalizers via the
dart_api.h
, we also need the behavior of (1), and we actually want to send objects to other isolates (that's why we resorted to using finalizers from thedart_api.h
in the first place.)We should introduce another marker interface that only has behavior 1.
Maybe the interfaces should even be related.
Ready for bike shedding on the name:
a.
KeepAlive
b.
IsolateGroupFinalizable
The marker interface should probably live in
dart:ffi
as well. Because it's mostly used when sending objects via FFI withHandle
s. Also it would enable relating the two interfaces, helping with documentation. But I can be convinced of other options.Use case:
cc @HosseinYousefi @mkustermann
The text was updated successfully, but these errors were encountered: