[foreign-abi] RFR: 8241017: Enhance AllocationScope to support "unbounded" mode

Ty Young youngty1997 at gmail.com
Mon Mar 16 04:44:32 UTC 2020


On 3/13/20 11:36 AM, Maurizio Cimadamore wrote:
> This patch adds support for allocation scopes whose size is not known statically; as such these new unbounded
> allocation scope can be used in more dynamic use cases where e.g. the amount of memory to be allocated depends on the
> result of other native calls.
>
> Internally, the bounded version works as before, and is the more optimized. The unbounded version is similar in spirit
> to the old Panama/foreign scope - where new segments are allocated depending on needs.
>
> I've enhanced the existing test covering allocation scopes to also cover the unbounded variants, as well as the bounded.


After reading the code from:


https://github.com/openjdk/panama-foreign/tree/fbf5ef776be35e38adb98e710aade0dd1e3b268b


I have some disagreements on the implementation. The expected behaviour, 
in my mind anyway, is that the returned MemoryAddress is *ALWAYS* just 
an offset of a larger, always same MemorySegment,


I guess what I'm really looking for here is dynamic memory allocation 
where the MemorySegment is just expanded on demand. 
UnboundedAllocationScope seems like a hacky workaround for dynamic 
memory allocation that could potentially cause bugs(*) and wastes 
potentially valuable memory(4KB is a bit much...).


* In that code might go looking for a value stored in the segment that 
is in fact on the previously allocated segment.


>
> -------------
>
> Commit messages:
>   - JDK-8241017: Enhance AllocationScope to support "unbounded" mode
>
> Changes: https://git.openjdk.java.net/panama-foreign/pull/53/files
>   Webrev: https://webrevs.openjdk.java.net/panama-foreign/53/webrev.00
>    Issue: https://bugs.openjdk.java.net/browse/JDK-8241017
>    Stats: 320 lines in 4 files changed: 240 ins; 25 del; 55 mod
>    Patch: https://git.openjdk.java.net/panama-foreign/pull/53.diff
>    Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/53/head:pull/53
>
> PR: https://git.openjdk.java.net/panama-foreign/pull/53


More information about the panama-dev mailing list