RFR: 8318678: Vector access on heap MemorySegments only works for byte[] [v2]
Per Minborg
pminborg at openjdk.org
Thu Oct 26 09:17:28 UTC 2023
On Wed, 25 Oct 2023 16:35:30 GMT, Chris Hegarty <chegar at openjdk.org> wrote:
>> 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.
I've removed the alignment checks.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16360#discussion_r1372844356
More information about the core-libs-dev
mailing list