RFR: 8318678: Vector access on heap MemorySegments only works for byte[]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Oct 25 13:57:33 UTC 2023


On Wed, 25 Oct 2023 13:08:06 GMT, Per Minborg <pminborg 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.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java line 750:

> 748:     AbstractMemorySegmentImpl requireSegmentConvertibleFor(MemorySegment segment, long offset, int elementByteSize)  {
> 749:         AbstractMemorySegmentImpl ams = (AbstractMemorySegmentImpl) segment;
> 750:         if (ams.maxAlignMask() > 1 && !ams.isAlignedForElement(offset, elementByteSize)) {

I don't think we should only check for maxAlignMask > 1 - you also want to check native segments, right?

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java line 755:

> 753:                     .map(Class::componentType)
> 754:                     .map(Object::toString)
> 755:                     .orElse("?");

orElseThrow?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16360#discussion_r1371805656
PR Review Comment: https://git.openjdk.org/jdk/pull/16360#discussion_r1371806618


More information about the core-libs-dev mailing list