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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Mar 13 21:52:05 UTC 2020


On Fri, 13 Mar 2020 17:19:45 GMT, Jorn Vernee <jvernee at openjdk.org> 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.
>
> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/UnboundedAllocationScope.java line 71:
> 
>> 70:                 sp = start + bytesSize;
>> 71:                 size += Utils.alignUp(bytesSize, bytesAlignment);
>> 72:                 return slice.baseAddress();
> 
> Aren't `sp` and `size` always the same? Are 2 separate fields really needed?

The idea is that size keeps track of total allocation size, sp is just a pointer into current segment and is reset
every time - unless I made a mistake

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

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


More information about the panama-dev mailing list