RFR: 8303040: linux PPC64le: Implementation of Foreign Function & Memory API (Preview) [v3]

Jorn Vernee jvernee at openjdk.org
Tue Mar 14 03:05:41 UTC 2023


On Mon, 13 Mar 2023 20:57:22 GMT, Martin Doerr <mdoerr at openjdk.org> wrote:

> Note that argument and return value passing works. I'm getting all values back. So, the native side seems to be ok. Only (one or two) values in `returnBox` are broken.

You mean you tested by returning each element of the array one by one?

If so, that rules out an issue with the downcall, or the struct not being in the right format (in the register), I think.

I suggest checking the bindings generated for the upcall, and seeing if they match what the native code does. This could be done in `jshell` for instance:


$ .\build\windows-fastdebug\images\jdk\bin\jshell.exe --enable-preview '--add-exports=java.base/jdk.internal.foreign.abi.x64.windows=ALL-UNNAMED' '--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED'

jshell> import java.lang.foreign.*
jshell> import java.lang.invoke.*
jshell> import static java.lang.foreign.ValueLayout.*
jshell> import jdk.internal.foreign.abi.x64.windows.CallArranger
jshell> MemoryLayout.structLayout(MemoryLayout.sequenceLayout(8, JAVA_BYTE))
$5 ==> [[8:b8]]
jshell> FunctionDescriptor.of($5, $5, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE)
$6 ==> ([[8:b8]]b8b8b8b8b8b8b8b8)[[8:b8]]
jshell> CallArranger.getBindings($6.toMethodType(), $6, true)
$7 ==> Bindings[callingSequence=jdk.internal.foreign.abi.CallingSequence at 396e2f39, isInMemoryReturn=false]
jshell> System.out.println($7.callingSequence().asString())
CallingSequence: {
  callerMethodType: (long,int,int,int,int,int,int,int,int)long
  calleeMethodType: (MemorySegment,byte,byte,byte,byte,byte,byte,byte,byte)MemorySegment
  FunctionDescriptor: ([[8:b8]]b8b8b8b8b8b8b8b8)[[8:b8]]  
  Argument Bindings:
    0: [Allocate[size=8, alignment=1], Dup[], VMLoad[storage=VMStorage[type=0, segmentMaskOrSize=15, indexOrOffset=1, debugName=rcx], type=long], BufferStore[offset=0, type=long, byteWidth=8]]
    1: [VMLoad[storage=VMStorage[type=0, segmentMaskOrSize=15, indexOrOffset=2, debugName=rdx], type=int], INT_TO_BYTE]
    2: [VMLoad[storage=VMStorage[type=0, segmentMaskOrSize=15, indexOrOffset=8, debugName=r8], type=int], INT_TO_BYTE]
    3: [VMLoad[storage=VMStorage[type=0, segmentMaskOrSize=15, indexOrOffset=9, debugName=r9], type=int], INT_TO_BYTE]
    4: [VMLoad[storage=VMStorage[type=3, segmentMaskOrSize=8, indexOrOffset=0, debugName=Stack at 0], type=int], INT_TO_BYTE]
    5: [VMLoad[storage=VMStorage[type=3, segmentMaskOrSize=8, indexOrOffset=8, debugName=Stack at 8], type=int], INT_TO_BYTE]
    6: [VMLoad[storage=VMStorage[type=3, segmentMaskOrSize=8, indexOrOffset=16, debugName=Stack at 16], type=int], INT_TO_BYTE]
    7: [VMLoad[storage=VMStorage[type=3, segmentMaskOrSize=8, indexOrOffset=24, debugName=Stack at 24], type=int], INT_TO_BYTE]
    8: [VMLoad[storage=VMStorage[type=3, segmentMaskOrSize=8, indexOrOffset=32, debugName=Stack at 32], type=int], INT_TO_BYTE]
  Return bindings:
    [BufferLoad[offset=0, type=long, byteWidth=8], VMStore[storage=VMStorage[type=0, segmentMaskOrSize=15, indexOrOffset=0, debugName=rax], type=long]]
}

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

PR: https://git.openjdk.org/jdk/pull/12708


More information about the core-libs-dev mailing list