BUG: SystemABI C_LONG and C_LONGLONG are the same
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri May 15 10:09:49 UTC 2020
On 15/05/2020 02:27, Ty Young wrote:
> The issue with using Constable is that often times the information is
> the same, so I'm going to end up with not only more garbage but a
> really huge struct layout for every struct.
Huge in what dimension? Source code? Memory footprint? ... ?
> without creating a ungodly amount of garbage.
What I'm suggesting is simply something like this:
public static final Optional<GroupLayout> LAYOUT = Optional.of(
MemoryLayout.ofStruct(
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE,
NativeInteger.class),
MemoryLayout.ofPaddingBits(32)
MemoryLayouts.C_LONGLONG.withAttribute(CROSSPOINT_TYPE,
NativeLongLong.class),
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE,
NativeInteger.class),
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE,
NativeInteger.class),
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE,
NativeInteger.class),
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE,
NativeInteger.class),
));
Of course, if you find this too verbose (even though I think this is, in
principle, machine generated code, so maybe that's less of a concern?) -
you can also define your layout constants off in a separate class:
class CrosspointLayouts {
MemoryLayout CP_INT =
MemoryLayouts.C_INT.withAttribute(CROSSPOINT_TYPE, NativeInteger.class);
MemoryLayout CP_LONGLONG =
MemoryLayouts.C_LONGLONG.withAttribute(CROSSPOINT_TYPE,
NativeLongLong.class)
//rinse and repeat
}
And then your struct simply becomes
public static final Optional<GroupLayout> LAYOUT = Optional.of(
MemoryLayout.ofStruct(
CP_INT,
MemoryLayout.ofPaddingBits(32)
CP_LONGLONG,
CP_INT,
CP_INT,
CP_INT,
CP_INT
));
What's wrong with this? Note that with this strategy you actually
embedded useful, domain-specific info into layouts. Assuming you always
use the layouts defined in your set of constants, you can always ask
questions like "what's the carrier for this layout?".
But I don't see the need for burdening the more general abi support with
this use case.
Maurizio
More information about the panama-dev
mailing list