[foreign-memaccess+abi] RFR: 8291639: Improve the ability to visualize a MemorySegment in human readable forms [v3]

Glavo duke at openjdk.org
Fri May 26 17:08:20 UTC 2023


On Fri, 26 May 2023 16:05:50 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to add a "Record Mapper" that allows `MemorySegment` instances to be projected onto `Record` types given `GroupLayout` instances.
>> 
>> Here is a simple example of how to use the mapper:
>> 
>> 
>>     private static final GroupLayout POINT_LAYOUT = MemoryLayout.structLayout(
>>             JAVA_INT.withName("x"),
>>             JAVA_INT.withName("y"));
>> 
>>     MemorySegment segment =  MemorySegment.ofArray(new int[]{3, 4});
>> 
>>     Point point = POINT_LAYOUT.recordMapper(Point.class)
>>           .apply(segment); // Point[x=3, y=4]
>> 
>> 
>> I think the implementation can be improved later, for example by de-duplicating handling of arrays and maybe add recursive "un-pealing" of multidimensional arrays.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Assert the invariant the typ is not Record itself

@minborg Thank you very much for your answer. Despite this, I am still a bit frustrated.

> Well, yes, but it is similarly suboptimal to just use records directly - as you can see from the RecordMapper implementation, there's quite a lot of "plumbing" that needs to occur so that fields can be extracted.

Maybe my thinking is too idealistic. My thought is that in theory the JIT compiler also understands the calling convention, so it can optimize in conjunction with scalar replacement (or Valhalla), use registers to pass parameters and accept return values ​​as much as possible, so that the call cost is close to native.

This may be me being too picky, I just hope that Panama performance has more room for optimization. It would be great if there is a better solution to these problems in the future.

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

PR Comment: https://git.openjdk.org/panama-foreign/pull/833#issuecomment-1564680589


More information about the panama-dev mailing list