[foreign-jextract] RFR: Generalize UpcallStub into NativeSymbol (jextract version)

Athijegannathan Sundararajan sundar at openjdk.java.net
Wed Oct 6 12:16:31 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).

Marked as reviewed by sundar (Committer).

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/592


More information about the panama-dev mailing list