[foreign-jextract] RFR: MemorySegmentPool + Allocator [v8]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu Apr 22 21:05:33 UTC 2021


On Thu, 22 Apr 2021 20:23:56 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

>> That's a pity JMH does not allow sub measurements
>
> I think that issue is related how JVM shapes code. If I'll write something like this 
> readSegment(s.memoryAddress.asSegment(size, scope));
> so I'll allocate a new segment based on address than the read performance goes up, and it's same as malloc version

Yeah - I confirm that if you add another getter for `MemoryPoolSegment::memorySegment`, like this:


@ForceInline
    public MemorySegment memorySegment(long size) {
      return memoryAddress.asSegment(size, scope);
    }

    
Then performance improve considerably. This smells like an inlining issue - e.g. the `size` value that is passed by the code to `getSegmentEntryBySize` is not recognized as the size of the segment - C2 doesn't seem to be able to see through it. There is too much control flow inside `getSegmentEntryBySize` - the trick is to create a "fresh" segment as close as possible to the application code.

The safe version of the API already does this, in fact suffers less from this issue (it's slower than malloc for smaller allocation sizes, but that has always been the case - but it's faster than the direct version!).

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

PR: https://git.openjdk.java.net/panama-foreign/pull/509


More information about the panama-dev mailing list