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

Maurizio Cimadamore mcimadamore at openjdk.org
Fri May 26 15:27:12 UTC 2023


On Fri, 26 May 2023 14:47:04 GMT, Glavo <duke at openjdk.org> wrote:

> Is it possible that we will get something like this in the future:

I believe record mapper is a "high-level" kind of mapping, so supporting this mapping from the linker out of the box would be too magic. Note also that, if you pull on that string, you might also want to express memory dereference directly using records. We thought about this kind of stuff but found it problematic because, while it's easy to read a segment "as a record" the other way around is not easy. As you point out there are lifetime issues, but also issues when it comes to writing unions (which fields of the record/union do we write?).

One of the strength of the Linker API (and FFM API) is that it is built out of very simple primitives, but it also allows composition. So, if you have a downcall which returns a segment, it is quite easy to adapt it to one that returns a record (same for var handles).

But records are only _one_ of the possible ways to map foreign types into Java-land (and one that has few limitations, as for unions). Other clients might prefer mapping structs/unions with simple classes which wrap a memory segment (which might not be too bad if these classes are Valhalla values). From a design perspective, the linker should be relatively agnostic about these kinds of high-level mappings (but should allow for tools that desire to do so, to provide said mappings).

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

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


More information about the panama-dev mailing list