On Wed, 25 Oct 2023 14:01:09 GMT, Maurizio Cimadamore <mcimadam...@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