openj9
openj9 copied to clipboard
[Part 2&3] FFI Upcall: generating thunk with the encoded signature
The changes mainly include the following code for thunk generation:
- the thunk memory allocation & release
- the encoding of the native signature intended for thunk
- the thunk generation (created by JIT)
Signed-off-by: Cheng Jin [email protected]
The change belongs to the issue intended for the upcall work at #15068.
Note:
- the code here might reply on the headers in Part 1 at #15083, in which case Part 1 must be merged at first prior to Part 2 & 3.
- the thunk generation code (
UpcallThunkGen.cpp
) was offered by @zl-wang with minor issues fixed and modifications to align with the coding standards in OpenJ9 - the thunk generation code is only implemented on AIX/PPC and Linux/PPC64LE for the moment while the code on other platforms are simply placeholders for compilation in Jenkins.
-
createUpcallThunk
inOutOfLineINL_jdk_internal_foreign_abi_ProgrammableUpcallHandler_allocateUpcallStub
andOutOfLineINL_jdk_internal_foreign_abi_UpcallLinker_allocateUpcallStub
is re-enabled here as it is disabled in Part 1 (native).
Reviewer: @tajila, @gacholio FYI: @DanHeidinga, @pshipton, @zl-wang
The changes have been updated based on the latest solution at https://github.com/ChengJin01/openj9/commit/f2b361181c71d2ef4bf70e730f5a097cabda6636 to avoid duplicating code in downcall & upcall.
I will need to update the code here once the code at https://github.com/eclipse-openj9/openj9/pull/15083 is merged given there might be overlapped code/conflicts to be resolved.
Hi @tajila, the code here is ready for review now after updating to resolve all conflicts.
@zl-wang Please review these changes
jenkins test sanity win jdk8
jenkins test sanity plinux jdk19
The failure at https://openj9-jenkins.osuosl.org/job/Build_JDK19_ppc64le_linux_Personal/17/console
15:27:40 /home/jenkins/workspace/Build_JDK19_ppc64le_linux_Personal/openj9/runtime/vm/UpcallThunkMem.cpp:189:3: error: 'Trc_VM_allocateThunkHeap_create_heap_failed' was not declared in this scope; did you mean 'Trc_VM_allocateThunkHeap_reserve_memory_failed'?
15:27:40 189 | Trc_VM_allocateThunkHeap_create_heap_failed(allocMemPtr, pageSize);
15:27:40 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15:27:40 | Trc_VM_allocateThunkHeap_reserve_memory_failed
was caused by the outdated j9vm.tdf
which I just updated against my local build & private branch with the latest tracepoints.
jenkins test sanity plinux jdk19
The compilation failure at https://openj9-jenkins.osuosl.org/job/Build_JDK19_ppc64le_linux_Personal/18/console
19:29:47 /home/jenkins/workspace/Build_JDK19_ppc64le_linux_Personal/openj9/runtime/vm/xl64/UpcallThunkGen.cpp: In function 'void* createUpcallThunk(J9UpcallMetaData*)':
19:29:47 /home/jenkins/workspace/Build_JDK19_ppc64le_linux_Personal/openj9/runtime/vm/xl64/UpcallThunkGen.cpp:202:56:
error: 'const J9InternalVMFunctions' {aka 'const struct J9InternalVMFunctions'} has no member named 'native2InterpJavaUpcall0'
19:29:47 202 | metaData->upCallCommonDispatcher = (void *)vmFuncs->native2InterpJavaUpcall0;
19:29:47 | ^~~~~~~~~~~~~~~~~~~~~~~~
was caused by the commented declarations of these functions in Part 1 at https://github.com/eclipse-openj9/openj9/pull/15083 given the dispatcher code for upcall is placed in Part 4 at https://github.com/eclipse-openj9/openj9/pull/15309. I just re-enabled these declarations (including j9nonbuilder.c
, vm_api.h
and intfunc.c
) to see how it goes in compilation.
jenkins test sanity plinux jdk19
If it still fails on other platforms (e.g on Windows) due to the missing implementation in the dispatcher, I will need to create a dummy file for dispatcher to let it pass the compilation for the moment.
jenkins compile win jdk19
The compilation failure on Windows at https://openj9-jenkins.osuosl.org/job/Build_JDK19_x86-64_windows_Personal/37/consoleText
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcall0
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcall1
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcallJ
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcallF
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcallD
[2022-08-31T03:23:40.394Z] intfunc.c.obj : error LNK2001: unresolved external symbol native2InterpJavaUpcallStruct
[2022-08-31T03:23:40.394Z] ..\j9vm29.dll : fatal error LNK1120: 6 unresolved externals
was caused by the missing implementation of the dispatcher, which requires a placeholder for compilation.
jenkins compile win jdk19
I just created a dummy file runtime\vm\UpcallVMHelpers.cpp
(only has empty body with all code removed) as the placeholder for dispatcher in upcall to see whether it passes compilation.
Windows build was successful.
jenkins test sanity plinux jdk19
jenkins compile win jd8
jenkins compile win jdk8