Open
Description
After #44589, the question becomes what can we do for non-leaf calls.
If the typed-data is an external typed-data, unwrapping it on non-leaf calls is fine.
- If the typed-data is internal, invoking the FFI call should throw.
- Similar to leaf-calls: The native code should not take ownership of the pointer.
- Similar to leaf-calls: There should be a reachability fence on the typed-data arguments if we load the untagged address before the FfiCallInstr.
Possible alternatives for avoiding buffer copies on non-leaf calls.
- Structure the API with
Pointer
s instead, likely nested in opaque classes that implementFinalizable
.- This runs into issues if one both wants to give access to this wrapper class which might have a finalizer and a typed-data which might have a finalizer for the same underlying data. Using
asTypedList
with a finalizer and then views on top of that to ensure there's only a single finalizer runs into the problems again that there's no
- This runs into issues if one both wants to give access to this wrapper class which might have a finalizer and a typed-data which might have a finalizer for the same underlying data. Using
- Enable checking on typed-data if it's external or not, then users can make a copy to native memory if it's not external.
- The downside here is non-predictable performance characters, sometimes an invocation will copy, and sometimes it wont.
- Adding the
Pointer
on theTypedData
with anExpando
- The issue here is that one would need to add a reachability fence manually after the FFI call that used the
Pointer
- The issue here is that one would need to add a reachability fence manually after the FFI call that used the