Return type presence must match error on handle creation

Jorn Vernee jorn.vernee at oracle.com
Fri Feb 21 12:38:31 UTC 2020


Hi Ty,

The exception that you are seeing is caused by a check that checks if 
the MethodType having a void return type matches if the 
FunctionDescriptor has a return layout.

if ((mt.returnType() ==void.class) == cDesc.returnLayout().isPresent())
     throw new IllegalArgumentException("return type presence must match!");

Since that looks like it's true in your case since you are passing 
MemoryLayouts.C_INT and int.class I suspect that the C_INT layout you 
are using is actually 'null' in this case, which results in the return 
layout being empty. We should check that better: 
https://bugs.openjdk.java.net/browse/JDK-8239780

Why is C_INT null? It seems like we are having some problems with 
circular initialization. If MemoryLayouts is clinited first everything 
works fine, but if one of the platform specific constant holders is 
clinited first the C_XXX constants will end up being null: 
https://bugs.openjdk.java.net/browse/JDK-8239784

Thanks for the report!

As a temporary workaround, you could try to force the MemoryLayouts 
clinit to run first, by having something like 
System.out.println(MemoryLayouts.C_CHAR); at the start of your main method.

Jorn

On 21/02/2020 05:32, Ty Young wrote:
> Hi,
>
>
> I'm trying to call the XNVCTRLQueryExtension function from NVXCtrl API 
> but am getting an error[1].
>
>
> The function is defined like so:
>
>
> Bool XNVCTRLQueryExtension (
>     Display *dpy,
>     int *event_basep,
>     int *error_basep
> );
>
>
> where Bool is defined as an int in Xlib_h(Display is an X server 
> display pointer).
>
>
> Java binding code is:
>
>
> this.address = NVCtrl_h.LIBRARY_LOOKUP.lookup("XNVCTRLQueryExtension");
>
> this.descriptor = FunctionDescriptor.of(MemoryLayouts.C_INT, false, 
> MemoryLayouts.C_POINTER, MemoryLayouts.C_POINTER, 
> MemoryLayouts.C_POINTER);
>
> this.type = MethodType.methodType(int.class, MemoryAddress.class, 
> MemoryAddress.class, MemoryAddress.class);
>
>
> However this gives the following error:
>
>
> Caused by: java.lang.IllegalArgumentException: return type presence 
> must match!
>     at 
> jdk.incubator.foreign/jdk.internal.foreign.abi.SharedUtils.checkFunctionTypes(SharedUtils.java:185)
>     at 
> jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.getBindings(CallArranger.java:95)
>     at 
> jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.CallArranger.arrangeDowncall(CallArranger.java:129)
>     at 
> jdk.incubator.foreign/jdk.internal.foreign.abi.x64.sysv.SysVx64ABI.downcallHandle(SysVx64ABI.java:72)
>     at 
> org.goliath.bindings.nvxctrl.functions.XNVCTRLQueryExtension.<init>(XNVCTRLQueryExtension.java:28)
>     at 
> org.goliath.bindings.nvxctrl.main.NVCtrl_h.<clinit>(NVCtrl_h.java:24)
>
>
>
> What's going on?
>
>
>
> [1] 
> https://github.com/NVIDIA/nvidia-settings/blob/master/src/libXNVCtrl/NVCtrlLib.h
>


More information about the panama-dev mailing list