Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8259054

Generate helper methods for converting from MemoryAddresses to function types in jextract

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: repo-panama
    • Fix Version/s: None
    • Component/s: tools

      Description

      While we currently have good support for passing Java methods wrapped as function pointers to native code so they can be called there, we are lacking a bit on the opposite front where function pointers (in the form of MemoryAddresses) are passed from native code to Java, and the user would like to invoke this function pointer.

      While it is technically possible to do this today by manually invoking CLinker.downcallHandle with the function pointer and an appropriate MethodType and FunctionDescriptor, the user has to manually figure out the needed type information, as it is currently not exposed in the generated jextract bindings.

      Even if the type information were to be exposed, it would have to be supplied manually. In this case it would be more useful if jextract generated helper methods in the functional interface types it generates, that can convert a MemoryAddress into a MethodHandle, or an instance of the functional interface, such as:

          public interface myHeader$foo$f {
              ...
              public static myHeader$foo$f ofAddress(MemoryAddress);
          }

      That way, when the user receives a function pointer from native code and would like to invoke it, they can easily do so using this helper method.

        Attachments

          Activity

            People

            Assignee:
            sundar Sundararajan Athijegannathan
            Reporter:
            jvernee Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: