Skip to content

[vm/ffi] Implement ExternalTypedData unwrapping to Pointers in non-leaf calls  #54856

Open
@dcharkes

Description

@dcharkes

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 Pointers instead, likely nested in opaque classes that implement Finalizable.
    • 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
  • 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 the TypedData with an Expando
    • The issue here is that one would need to add a reachability fence manually after the FFI call that used the Pointer

cc @mkustermann @craiglabenz @Piinks

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffitriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions