[foreign-jextract] Integrated: Generalize UpcallStub into NativeSymbol (jextract version)
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Oct 6 12:47:21 UTC 2021
On Wed, 6 Oct 2021 12:09:14 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This patch fixes jextract to use NativeSymbol.
>
> Overall it was a useful exercise, as it pointed out some inconsistencies in our generation startegy for upcalls. Jextract currently generates the following two methods:
>
>
> static NativeSymbol allocate(CXCursorVisitor fi) { ... }
> static NativeSymbol allocate(CXCursorVisitor fi, ResourceScope scope) { ... }
> static CXCursorVisitor ofAddress(MemoryAddress addr) { ... }
>
>
> The first two are used to jusr create an upcall from a lambda; while the third is used to turn an address into a functional interface which can be called from Java code.
>
> In both the first and last case, there's a `ResourceScope` parameter missing, I think. Creating an upcall always needs a scope; similarly, when creating a custom `NativeSymbol` from a native address, we need to associate a scope to it too (which determines when it's ok to call the native symbol).
>
> I've rectified jextract to take scopes in all the right places. Since for structs and global variables we emit functional interface getters, some changes went in there too. In the case of global variables, there's no need to pass a scope (as a global variable has the global scope). But in the case of a struct access, the user does need to pass a scope (inferring the scope from the struct segment is possible, but most likely not the right/general thing to do).
This pull request has now been integrated.
Changeset: ddcd5741
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.java.net/panama-foreign/commit/ddcd5741b1817f038299033b22ab89683a1bed8e
Stats: 52 lines in 9 files changed: 6 ins; 17 del; 29 mod
Generalize UpcallStub into NativeSymbol (jextract version)
Reviewed-by: sundar
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/592
More information about the panama-dev
mailing list