[foreign-memaccess] RFR: 8252504: Add a method to MemoryLayout which returns a offset-computing method handle
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Nov 19 20:51:10 UTC 2020
On Thu, 19 Nov 2020 19:58:12 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> 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).
My recollection of this code is that when you get to generating the handle, you already have the unspecified paths in the stride array. Look at the places for when a new stride is set - I think it should match the places where you need the info as well (that is `PathElement::sequenceElement()` and `PathElement::sequenceElement(long, long)`).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/396
More information about the panama-dev
mailing list