[foreign-memaccess] RFR: 8252504: Add a method to MemoryLayout which returns a offset-computing method handle
Jorn Vernee
jvernee at openjdk.java.net
Thu Nov 19 20:02:12 UTC 2020
On Thu, 19 Nov 2020 18:01:39 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This PR adds two new methods: `bitOffsetHandle` and `byteOffsetHandle` to `MemoryLayout`, that can be used to create method handles that can compute the effective offset of a layout element given a set of additional `long` indexes.
>>
>> I also cleaned up a leftover in the javadoc of bitOffset and byteOffset where an API note was stating that `sequenceElement()` layout path elements would be interpreted as `sequenceElement(0)`, but they were actually being rejected outright (as they should).
>>
>> I also added some tests to cover the corner case where an UnsupportedOperationException was being thrown. (some of the churn in the tests is from introducing static imports. I hope it's not too noisy).
>
> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/LayoutPath.java line 205:
>
>> 203: if (cur.enclosing.layout instanceof SequenceLayout
>> 204: && cur.elementIndex == UNSPECIFIED_ELEM_INDEX) { // sequenceElement()
>> 205: MethodHandle collector = MethodHandles.insertArguments(MH_ADD_SCALED_OFFSET, 2, cur.layout.bitSize());
>
> You already have the `strides` array for doing this? E.g. I don't think there's a need to walk the layout paths upwards and to get their size - all you need is in the stride array.
We need to walk to inspect the element indices to see if we have a sequenceElement path element with an unspecified index. Could replace the `cur.layout.bitSize` with a lookup into the strides array maybe, but I think that would require keeping track of a separate index as well. (I'll take a look).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/396
More information about the panama-dev
mailing list