[foreign-memaccess+abi] RFR: 8301801: Implement arena-centric API
Jorn Vernee
jvernee at openjdk.org
Thu Feb 9 18:49:24 UTC 2023
On Thu, 9 Feb 2023 16:28:27 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> This patch implements the API proposal described here:
>>
>> https://cr.openjdk.java.net/~mcimadamore/panama/scoped_arenas.html
>>
>> The main changes are:
>>
>> * Static factories `MemorySegment::allocateNative` are gone;
>> * The static factory `SegmentAllocator::nativeAllocator` is also gone;
>> * `SegmentScope` moved as nested class in `MemorySegment` (e.g. `MemorySegment.Scope`);
>> * Tweak methods accepting `SegmentScope` to accept `Arena` instead;
>> * Simplify `Arena` API, by removing predicates (`isCloseable`/`isAccessibleBy`) and by dropping `whileAlive`;
>> * Change arena factories to use `of` prefix instead of `open` - and rename `auto()` to `ofAuto()`.
>>
>> The API changes are rather straightforward, but they lead to several shallow test and microbenchmark changes, so the number of affected file is quite big (mostly because of the rename `openConfined` -> `ofConfined`).
>>
>> A javadoc of the proposed changes is available here:
>>
>> http://cr.openjdk.java.net/~mcimadamore/panama/scoped_arena_interface_lump_predicates/
>
> src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 157:
>
>> 155:
>> 156: private static MemorySegment bufferCopy(MemorySegment dest, MemorySegment buffer) {
>> 157: return dest.asUnbounded().copyFrom(buffer);
>
> Why is this change needed? The destination segment should already have the right size.
>
> Looking at the current code, this is used for upcall IMR, where we get a pointer from native code to copy the return value into. When that pointer is boxed up, we should be attaching the right size to it (since we know the layout of the return value).
Okay, it looks like for in memory return on e.g. SysV, we are using just a plain `C_POINTER` layout without a pointee layout attached, so the boxed address should already have unbounded size.
> test/jdk/java/foreign/TestByteBuffer.java line 185:
>
>> 183: try (Arena arena = Arena.ofConfined()) {
>> 184: Arena scope = arena;
>> 185: MemorySegment segment = scope.allocate(tuples);;
>
> Suggestion:
>
> MemorySegment segment = arena.allocate(tuples);
Looks like there are several more like this in the rest of the tests as well.
If you don't feel like they're worth cleaning up then I'm fine with that as well.
-------------
PR: https://git.openjdk.org/panama-foreign/pull/781
More information about the panama-dev
mailing list