RFR: 8343188: Investigate ways to simplify MemorySegment::ofBuffer

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Oct 30 18:39:11 UTC 2024


On Tue, 29 Oct 2024 14:51:33 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to improve `MemorySegment::ofBuffer` making it more amenable to inlining and generally improving performance.
> 
> Testing successfully on tier1-3

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 541:

> 539: 
> 540:     @ForceInline
> 541:     private static AbstractMemorySegmentImpl arrayFreeSegment(Buffer b, long offset, long length) {

the names `arrayFreeSegment` and `arrayBackedSegments` seem a bit confusing. I'd suggest `ofDirectBuffer` and `ofHeapBuffer`

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 546:

> 544:         }
> 545:         final UnmapperProxy unmapper = NIO_ACCESS.unmapper(b);
> 546:         return unmapper == null

I would feel more at ease if the creation of segments went through SegmentFactories (this is not a new issue in this PR)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21764#discussion_r1823195381
PR Review Comment: https://git.openjdk.org/jdk/pull/21764#discussion_r1823193123


More information about the core-libs-dev mailing list