RFR: 8318678: Vector access on heap MemorySegments only works for byte[]
Chris Hegarty
chegar at openjdk.org
Wed Oct 25 16:38:38 UTC 2023
On Wed, 25 Oct 2023 14:01:09 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This PR proposes removing the restriction that only heap `MemorySegment` wrapping a `byte` array can be accessed by Vectors. Now any array type can be used provided the element alignment constraints are respected.
>
> test/jdk/jdk/incubator/vector/AbstractVectorLoadStoreTest.java line 118:
>
>> 116: private static boolean canBeConverted(IntFunction<MemorySegment> function, ValueLayout elementLayout) {
>> 117: // Create a sample to analyze
>> 118: MemorySegment s = function.apply(Long.BYTES);
>
> I believe that a good way to test this is the following:
> * each vector type operates as having a given element layout - for instance, you can imagine the layout for IntVector to be `JAVA_INT` and so forth
> * asking whether you load a segment into a vector is the same as asking whether you can access the segment, at offset 0L, with the layout associated with the vector (see above) - that is if MS::get throws, then vector load should also throw (and viceversa)
Vectors use and have in their docs, a layout with a byte alignment of 1. e.g. from `IntVector`
ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1)
Can the `fromMemorySegment` not just behave similarly? I get that alignment is preferable, but does it need to be enforced? If so, then maybe the `ELEMENT_LAYOUT` and example in the javadoc needs to be updated.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16360#discussion_r1372042718
More information about the core-libs-dev
mailing list