MemorySegment.close() is not idempotent

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Mar 15 13:45:05 UTC 2021


Thanks for taking a look.

Cheers
Maurizio

On 15/03/2021 13:38, forax at univ-mlv.fr wrote:
> ----- Mail original -----
>> De: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
>> À: "Remi Forax" <forax at univ-mlv.fr>, "panama-dev at openjdk.java.net'" <panama-dev at openjdk.java.net>
>> Envoyé: Lundi 15 Mars 2021 11:53:31
>> Objet: Re: MemorySegment.close() is not idempotent
>> Hi Remi,
>> this kind of issues is gonna be superseded by the upcoming work in:
>>
>> https://urldefense.com/v3/__https://github.com/openjdk/panama-foreign/pull/466__;!!GqivPVa7Brio!NELV5KZkPylRdV2Y3NrzCeOrx_ykNDqIve5YaOmHPbVui21SuaLH9LRvEobiDL-_Di5Fzrg$
>>
>> As part of that work, MemorySegment will lose the AutoCloseable
>> interface, and lifecycle will be managed in a different entity, called
>> ResourceScope (which is attached onto a segment).
>>
>> Now, closing ResourceScope is still not idem-potent, but I believe that,
>> with the new API, closing a scope twice is something you might want to
>> get notified about, as it 99% signals a bug in your code.
>>
>> I think it would be great if you could adjust the experiment to the new
>> API and see how much of a problem that is in there?
> I will, but not before next week end :(
>
>> P.S.
>> in the new API, if two resources (e.g. unsigned and signed) have same
>> lifecycle, they should be backed by same ResourceScope abstraction.
> Ok, i will take a look.
>
>> Maurizio
> Rémi
>
>> On 15/03/2021 09:11, Remi Forax wrote:
>>> To play with panama.foreign, i've partially re-implement the Apache Arrow [1]
>>> columnar format in pure Java.
>>> So i've a bunch of dataset class that are wrappers of one or two MemorySegment
>>> (two if the data can be nullable) that represent a column of data.
>>>
>>> I stumble on is the fact that a MemorySegment can not be closed more than once.
>>>   From dataset, i can be wrapped to another one, think by example the unsigned int
>>>   dataset being a wrapper on top on the signed one, but they share the same
>>>   MemorySegment.
>>>
>>> As a user i want to write something like
>>>     try(var dataset = IntDataSet.from(MemorySegment.allocateMemory(5 * 4));
>>>         var unsignedDataset = dataset.asUnsigned()) {
>>>       ...
>>>     }
>>>
>>> the problem is that the MemorySegment.close() is not idempotent, so i've to
>>> check myself (with isAlive()) if the MemorySegment of a dataset has already
>>> been closed or not.
>>>
>>> Did i miss something ?
>>>
>>> regards,
>>> Rémi
>>>
>>> [1] https://urldefense.com/v3/__https://arrow.apache.org/docs/index.html__;!!GqivPVa7Brio!NELV5KZkPylRdV2Y3NrzCeOrx_ykNDqIve5YaOmHPbVui21SuaLH9LRvEobiDL-_i8IyKBA$


More information about the panama-dev mailing list