openj9 icon indicating copy to clipboard operation
openj9 copied to clipboard

[Part 2&3] FFI Upcall: generating thunk with the encoded signature

Open ChengJin01 opened this issue 2 years ago • 2 comments

The changes mainly include the following code for thunk generation:

  1. the thunk memory allocation & release
  2. the encoding of the native signature intended for thunk
  3. the thunk generation (created by JIT)

Signed-off-by: Cheng Jin [email protected]

ChengJin01 avatar Jun 13 '22 17:06 ChengJin01

The change belongs to the issue intended for the upcall work at #15068.

Note:

  1. 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.
  2. 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
  3. 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.
  4. createUpcallThunk in OutOfLineINL_jdk_internal_foreign_abi_ProgrammableUpcallHandler_allocateUpcallStub and OutOfLineINL_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

ChengJin01 avatar Jun 13 '22 17:06 ChengJin01

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.

ChengJin01 avatar Jun 23 '22 16:06 ChengJin01

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.

ChengJin01 avatar Aug 17 '22 17:08 ChengJin01

Hi @tajila, the code here is ready for review now after updating to resolve all conflicts.

ChengJin01 avatar Aug 17 '22 22:08 ChengJin01

@zl-wang Please review these changes

tajila avatar Aug 25 '22 19:08 tajila

jenkins test sanity win jdk8

tajila avatar Aug 30 '22 19:08 tajila

jenkins test sanity plinux jdk19

tajila avatar Aug 30 '22 19:08 tajila

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.

ChengJin01 avatar Aug 30 '22 20:08 ChengJin01

jenkins test sanity plinux jdk19

knn-k avatar Aug 30 '22 23:08 knn-k

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.

ChengJin01 avatar Aug 31 '22 00:08 ChengJin01

jenkins test sanity plinux jdk19

knn-k avatar Aug 31 '22 01:08 knn-k

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.

ChengJin01 avatar Aug 31 '22 01:08 ChengJin01

jenkins compile win jdk19

knn-k avatar Aug 31 '22 01:08 knn-k

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.

ChengJin01 avatar Aug 31 '22 03:08 ChengJin01

jenkins compile win jdk19

knn-k avatar Aug 31 '22 03:08 knn-k

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.

ChengJin01 avatar Aug 31 '22 03:08 ChengJin01

Windows build was successful.

knn-k avatar Aug 31 '22 05:08 knn-k

jenkins test sanity plinux jdk19

knn-k avatar Aug 31 '22 05:08 knn-k

jenkins compile win jd8

tajila avatar Aug 31 '22 13:08 tajila

jenkins compile win jdk8

tajila avatar Aug 31 '22 13:08 tajila