experiments in panama code generation
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Feb 7 17:43:08 UTC 2022
On 07/02/2022 16:18, Maurizio Cimadamore wrote:
>
> On 06/02/2022 02:38, Michael Zucchi wrote:
>> Structures and unions are similar. Classes are typed holders of
>> MemorySegment and have normal java getters and setters, anything can
>> be renamed to be more java-like, fields can be excluded if they're
>> private or not useful, can be read/write and indexed acceess is
>> optional. It's quit a pity you can't implement Addressable as it
>> would just be so much tidier than having to reimplement the same
>> thing for the same purpose but in an incompatible way.
>
> Actually, we did some back and forth on this. There is no reason as to
> why Addressable could not be unsealed. I had in mind cases where
> structs would want to implement this - but then when reviewing it was
> decided it was better to start tighter and relax later on as required.
>
> Your use case seems to be similar to what I had in mind - and seems a
> good argument towards opening up Addressable.
Hit "Send" too fast. There were actually reasons as to why having custom
subtypes implementing Addressable might not be as useful as it seems at
first.
I captured that here:
https://bugs.openjdk.java.net/browse/JDK-8281382
Long story short - instead of mapping StructFoo down to an address - if
you have a MemorySegment, have a MS accessor instead, as that will work
with the linker in the "correct" way (e.g. by keeping the segment alive
for the duration of the call).
In other words, Addresable is, mostly, an interface used by the foreign
API to denote "by-ref" entities, whose temporal bounds have to be
reasoned upon in various ways. Having custom "by-ref" is possible, but
it's more than just having custom "Addressable" subtypes (you need a way
to get at the scope too).
Maurizio
>
> Maurizio
>
More information about the panama-dev
mailing list