downcalls, fixed-sized ABI types
Michael Zucchi
notzed at gmail.com
Mon Jan 20 22:00:09 UTC 2020
On 20/1/20 7:50 pm, Ty Young wrote:
> ABI can be ignored if you want. ABI/ValueLayouts APIs were created to
> work around all the hard-coded byte sizes which could (potentially)
> cause bugs[1].
No it can't, at least on the foreign-abi branch.
If you try using the sized types (the MemoryTypes.*, not
MemoryTypes.SysV.*) then SystemABI.downcallHandle() will throw an
exception because they're missing a required annotation. As 'attached'
below.
Anyway Maurizio's response makes it clear it's still work in progress.
Cheers,
Michael
This works:
memcpy = abi.downcallHandle(lib.lookup("memcpy"),
MethodType.methodType(void.class, new
Class[] { MemoryAddress.class,
MemoryAddress.class,
long.class,
}),
FunctionDescriptor.ofVoid(false,
MemoryLayouts.SysV.C_POINTER,
MemoryLayouts.SysV.C_POINTER,
MemoryLayouts.SysV.C_LONG));
This:
memcpy = abi.downcallHandle(lib.lookup("memcpy"),
MethodType.methodType(void.class, new
Class[] {
MemoryAddress.class,
MemoryAddress.class,
long.class,
}),
FunctionDescriptor.ofVoid(false,
MemoryLayouts.SysV.C_POINTER,
MemoryLayouts.SysV.C_POINTER,
MemoryLayouts.BITS_64_LE));
Will throw:
Caused by: java.lang.IllegalStateException: Unexpected value layout:
could not determine ABI class
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.classifyValueType(CallArranger.java:467)
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.classifyType(CallArranger.java:639)
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.classifyLayout(CallArranger.java:654)
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger$UnboxBindingCalculator.getBindings(CallArranger.java:350)
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.arrangeDowncall(CallArranger.java:126)
at
jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.SysVx64ABI.downcallHandle(SysVx64ABI.java:72)
More information about the panama-dev
mailing list