[foreign-memaccess] RFR 8230449: Simplify creation of handles for memory slices
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Sep 3 14:55:00 UTC 2019
On 03/09/2019 15:25, Jorn Vernee wrote:
>
> Hi,
>
> Some comments:
> - MemoryLayout.java; The javadoc should be updated from "if the step
> factor is < 0" -> "is 0", since it can also be negative.
> - LayoutPathImpl.java; Could use a helper method to do the sequence
> index check (code is duplicated between 2 `sequenceElement` methods).
> Also, the `step == 0` check is done in the
> PathElement::sequenceElement already.
>
Well spotted - will fix
>
> Lastly, I'm not so sure about the last check for invalid step factor.
> It would still be valid to access a single element when the coordinate
> passed to the VH is 0, but this check blocks that.
>
The idea is that if you pass a step factor that is bigger than the
selected sequence slice.
It's true that, in general, we provide no guarantee for out-of-bound
indices in array-like VH - but I guess I saw this as a user-mistake and
wanted to prevent it.
Now that I think more, I guess I see that, by removing that check, we
would actually be able to produce VH which are capable of accessing
exactly ONE element, which I guess can come in handy in certain cases.
Maurizio
> Rest looks good.
>
> Cheers,
> Jorn
>
> On 02/09/2019 17:27, Maurizio Cimadamore wrote:
>> Hi,
>> the foreign memory API is pretty good at expressing access to
>> multi-dimensional data, e.g. by allowing to define custom strides and
>> offsets. There are however some limitations that limit the
>> expressiveness of the API when it comes to denote complex
>> VarHandle-based views of contiguous chunks of memory:
>>
>> 1) It is not possible to use negative strides (which makes it
>> impossible e.g. to create a VarHandle which returns the contents of
>> the memory region "in reverse order")
>> 2) there's no way in the PathElement API to select a 'slice' of a
>> sequence layout (e.g. from start given start index, with given step)
>>
>> The following webrev aims at closing this gap:
>>
>> http://cr.openjdk.java.net/~mcimadamore/panama/8230449/
>>
>> P.S.
>> To allow negative strides I had to remove a validation of the stride
>> in the combinator API which ensured that the stride was greater than
>> the offset + carrierSize. I believe this restriction to be a tad
>> obscure and not a fundamental one (this was also pointed out by Jorn
>> when I added the restriction in the first place), so I'm ok to drop
>> it in name for more expressiveness.
>>
>> Maurizio
>>
More information about the panama-dev
mailing list