[foreign-jextract] RFR: Generalize UpcallStub into NativeSymbol (jextract version)
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Oct 6 12:16:31 UTC 2021
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).
-------------
Commit messages:
- Fix references to CLinker.UpcallStub
Changes: https://git.openjdk.java.net/panama-foreign/pull/592/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=592&range=00
Stats: 52 lines in 9 files changed: 6 ins; 17 del; 29 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/592.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/592/head:pull/592
PR: https://git.openjdk.java.net/panama-foreign/pull/592
More information about the panama-dev
mailing list