[foreign-abi] RFR: 8248420: Add a variant of VaList::make which takes a NativeScope
Jorn Vernee
jvernee at openjdk.java.net
Thu Jul 9 20:35:46 UTC 2020
On Thu, 9 Jul 2020 20:29:43 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/CSupport.java line 162:
>>
>>> 161: * That means that if this va list was created with the {@link #make(Consumer)} method, closing
>>> 162: * this va list will also free the argument space, and make the copy unusable.
>>> 163: *
>>
>> I don't fully have a grasp on this note. Not sure I understand the 'view' and 'argument space'. My guess is that this
>> means for the content of a MS argument. Do we have a test case for this note?
>
> A VaList is really only a 'view' of a set of arguments stored elsewhere. In native code the place where the arguments
> are stored (i.e. the 'argument space') is on the stack, so the memory will get cleaned up automatically. But, if we
> create a VaList on the Java side we need to do an explicit off-heap allocation and later call free to clean up the
> memory that stores the arguments. This argument space is freed when calling `close()` on the VaList. So, if you
> `copy()` a VaList, only the 'view' part is copied, but not the memory that holds the arguments.
I'm thinking of maybe dropping the VaList::make overload that doesn't take a NativeScope, so that the memory for the
arguments will always be managed by a NativeScope, and it doesn't have to piggyback on VaList::close
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/237
More information about the panama-dev
mailing list