Pinning of on-heap MemorySegment

Yasumasa Suenaga suenaga at oss.nttdata.com
Mon Aug 28 07:29:07 UTC 2023


Hi all,

I'm very interested in FFM, especially generate assembly code in Java and calling them with FFM [1].

I think one of the performance neck is MemorySegment because all of on-heap regions should be copied into off-heap region (native segment) when they are referred from foreign function. So I'm expecting to implement sort of pinning operation for on-heap MemorySegment like a JNI. I guess it is mentioned in FFM update in last month [2], however "Pinning of heap segments" does not have any links - I guess nobody is working for this yet. Do you have any updates for pinning?

I've played them with both OpenJDK 22 with pinning support [3] and ffmasm (hand-assembler for Java powered by FFM) [4]. I added pin/unpin method into Unsafe, and they are called by HeapMemorySegmentImpl. Finally I got about 16x performance gain compared to non-pinning code [5] on my laptop.

I guess FFM API reaches to goal step by step, but it is still a preview in JDK 21. I hope that pinning feature is supported into JDK 22 because I believe we can leverage FFM for more fields! I'm happy to contribute/help to implement pinning feature if it needs.


Thanks,

Yasumasa


[1] https://github.com/YaSuenag/ffmasm
[2] https://mail.openjdk.org/pipermail/panama-dev/2023-July/019510.html
[3] https://github.com/YaSuenag/jdk/commit/f0a9b3705b3ecdf3dbb6b80cac9d53456f08f967
[4] https://github.com/YaSuenag/ffmasm/commit/925608538b936db1b311ae84e12fa0252058b7f4
[5] https://github.com/YaSuenag/ffmasm/blob/ffm-pinning/benchmarks/vectorapi/src/main/java/com/yasuenag/ffmasm/benchmark/vectorapi/VectorOpComparison.java


More information about the panama-dev mailing list