[foreign-jextract] RFR: API refresh - part two (jextract edition)
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Oct 7 17:11:34 UTC 2021
This patch fixes jextract to work with the latest API changes.
The patch reintroduces overloads for foreign function wrappers which take a scope (since ResourceScope is no longer a subtype of SegmentAllocator).
We will consider later whether to drop these overloads; it is likely that the majority of jextract clients will already have an allocator somewhere, so the extra code is not necessary. On the other hand, if we want overloads, then I think it would also be useful to add an overload that takes a `MemorySegment` and converts it into a `prefixAllocator` (so that clients can store result of foreign function which returns a struct-by-value in a pre-existing segments).
I've made some improvements to the string conversion logic; in a lot of places we were creating a scope, then doing a malloc to allocate a temporary CXString, then extract a Java String from the CXString, and dispose/free the CXString. Since jextract is single-threaded, I replaced all that with an high-order function which takes a segment supplier, and uses a prefix allocator under the hood. This should be way more efficient than what we had - and string conversion is quite frequent in libclang (e.g. `CXCursor::spelling`).
The patch passes all tests.
-------------
Commit messages:
- Merge branch 'foreign-jextract' into cleanup_allocator+jextract
- Use a prefix allocator for string conversions
- Fix jextract to reflect latest API changes
- Merge branch 'cleanup_allocator' into cleanup_allocator+jextract
- Some more javadoc fixes on ResourceScope
- Revert CallOverheadHelper to use shared/confined points
- Update src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ResourceScope.java
- Update src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SegmentAllocator.java
- Update src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ResourceScope.java
- Update src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ResourceScope.java
- ... and 22 more: https://git.openjdk.java.net/panama-foreign/compare/ea1e0d6e...8af282d7
Changes: https://git.openjdk.java.net/panama-foreign/pull/594/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=594&range=00
Stats: 201 lines in 18 files changed: 99 ins; 26 del; 76 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/594.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/594/head:pull/594
PR: https://git.openjdk.java.net/panama-foreign/pull/594
More information about the panama-dev
mailing list