Skip to content

[FFI] Fix the issue with the struct FF/DD in upcall on z/OS - #20018

Merged
tajila merged 1 commit into
eclipse-openj9:masterfrom
ChengJin01:ffi_upcall_ff_dd_struct_fprs_zos
Aug 30, 2024
Merged

[FFI] Fix the issue with the struct FF/DD in upcall on z/OS#20018
tajila merged 1 commit into
eclipse-openj9:masterfrom
ChengJin01:ffi_upcall_ff_dd_struct_fprs_zos

Conversation

@ChengJin01

Copy link
Copy Markdown

[FFI] Fix the issue with the struct FF/DD in upcall on z/OS

The changes resolve the issue with the register mapping for the
struct FF/DD or its variants in upcall on z/OS by categorizing
them into ALL_SP/ALL_DP placed on FPRs while other non-complex
type are categorized into AGGREGATE_OTHER placed on GPRs.

Fixes: #19952

Signed-off-by: ChengJin01 jincheng@ca.ibm.com

@ChengJin01 ChengJin01 added comp:vm project:panama Used to track Project Panama related work os:zos labels Aug 19, 2024
@ChengJin01
ChengJin01 requested review from tajila and zl-wang August 19, 2024 21:30
@ChengJin01

ChengJin01 commented Aug 19, 2024

Copy link
Copy Markdown
Author

Reviewer: @zl-wang (the code related to the encoding signature), @tajila (the FFI code in java)
FYI: @dchopra001, @r30shah, @joransiu, @pshipton

@ChengJin01

Copy link
Copy Markdown
Author

The PR has been verified with FFI specific test suites in OpenJ9.

Comment thread runtime/vm/LayoutFFITypeHelpers.hpp
@zl-wang

zl-wang commented Aug 20, 2024

Copy link
Copy Markdown
Contributor

also, is there any special treatment in zOS ABI for single-member struct/union? something like:

struct {
   int me;
}

Hopefully no ... such that it is good as it is.

@r30shah

r30shah commented Aug 20, 2024

Copy link
Copy Markdown
Contributor

also, is there any special treatment in zOS ABI for single-member struct/union? something like:

If the passing parameter is union, it will regardless of member type, it will be passed in GPR. For the single element struct, it will be in GPR as well (whether it is Floating point or not).

Comment thread runtime/vm/LayoutFFITypeHelpers.hpp
Comment thread runtime/vm/LayoutFFITypeHelpers.hpp
@zl-wang

zl-wang commented Aug 21, 2024

Copy link
Copy Markdown
Contributor

If the passing parameter is union, it will regardless of member type, it will be passed in GPR. For the single element struct, it will be in GPR as well (whether it is Floating point or not).

for union treated as you described, is it limited to single-member and no-more-than-8-byte? or, you meant any union?
how about nested single-member struct? something like: struct { struct {int a; int b;} c; } similar questions as well.

@r30shah

r30shah commented Aug 21, 2024

Copy link
Copy Markdown
Contributor

for union treated as you described, is it limited to single-member and no-more-than-8-byte? or, you meant any union?
how about nested single-member struct? something like: struct { struct {int a; int b;} c; } similar questions as well.

According to LE Vendor reference [1], for argument passing, any aggregate type that is not union and contains exactly two floating point types of same size, is considered complex type. All other parameters from the argument lists are passed in GPR1-3 if available (With exception of floating point type.

So the case you shared, if we have nested single member struct, as the aggregate has only one member, it will be passed in available GPRs.

[1]. https://www.ibm.com/docs/en/SSLTBW_2.5.0/pdf/ceev100_v2r5.pdf

@zl-wang

zl-wang commented Aug 21, 2024

Copy link
Copy Markdown
Contributor

ok ... that makes it clear. the implementation only needs to tighten up on a few cases mentioned above, and we are good to go.

@ChengJin01

ChengJin01 commented Aug 22, 2024

Copy link
Copy Markdown
Author

@zl-wang, is there is anything left to be updated against the clarification by @r30shah? If no more concern, we should be able to get this merged asap given we've got a bunch of Jtreg test suites to be verified with fix.

@zl-wang

zl-wang commented Aug 23, 2024

Copy link
Copy Markdown
Contributor

@ChengJin01 at least three categorization bugs I can see, mentioned previously:

  1. struct { float a[2]; } should not be complex (even though ALL_SP and 8-byte in size);
  2. union { float a[2]; float b} should not be complex (even though ALL_SP and 8-byte in size);
  3. struct { struct {float a; float b;} c;} should not be complex either (even though ALL_SP and 8-byte in size); (@r30shah agree? i am not sure about this case)
    while you are fixing these, keep in mind the few being-complex cases mentioned previously.

@ChengJin01

ChengJin01 commented Aug 23, 2024

Copy link
Copy Markdown
Author

@ChengJin01 at least three categorization bugs I can see, mentioned previously:

1. `struct { float a[2]; }`     should not be complex (even though ALL_SP and 8-byte in size);

2. `union { float a[2];  float b}`  should not be complex (even though ALL_SP and 8-byte in size);

3. `struct { struct {float a; float b;} c;} `should not be complex either (even though ALL_SP and 8-byte in size);  (@r30shah  agree? i am not sure about this case)
   while you are fixing these, keep in mind the few being-complex cases mentioned previously.

@zl-wang,

As for case 2 union { float a[2]; float b}, it is treated as non-complex in this PR (the code in isStructWithFFOrDD already excludes any union type in the case of ALL_SP in 8 bytes) (the test case is

public void test_addFloatAndFloatsFromUnionWithNestedFloatArrayByUpcallMH() throws Throwable {
in OpenJ9 which is already verified with the fix).

As for case 3 struct { struct {float a; float b;} float c;} (is it struct { struct {float a; float b;}} ?) , it is more than 8 bytes which is out of our scope in discussion (which is definitely non-complex that is already covered in this PR) (the test case is

public void test_addFloatAndFloatsFromNestedStructByUpcallMH() throws Throwable {
in OpenJ9 which is already verified with the fix).

@r30shah

r30shah commented Aug 23, 2024

Copy link
Copy Markdown
Contributor

I agree with the cases @zl-wang shared, all those should be considered non complex.

@ChengJin01

Copy link
Copy Markdown
Author

@dchopra001,

please help confirm whether these 3 cases above are covered in this PR against z/OS ABI as the fix is totally based on z/OS ABI (my understanding is that case 2 & 3 should be addressed as explained at #20018 (comment)).

@ChengJin01

Copy link
Copy Markdown
Author

@zl-wang & @r30shah,

Do the rules also apply to double?
e.g.

struct { double a[2]; } should not be complex (even though ALL_DP and 16-byte in size);
union { double a[2];  double b} should not be complex (even though ALL_DP and 16-byte in size);
struct { struct {double a; double b;}} should not be complex either (even though ALL_DP and 16-byte in size);

If so, we will need to unify the code to handle them altogether.

@r30shah

r30shah commented Aug 23, 2024

Copy link
Copy Markdown
Contributor

@ChengJin01 Yes , rules include all floating point types, so doubles as well.

@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch from e035eea to 404d9fb Compare August 23, 2024 16:18
@ChengJin01

ChengJin01 commented Aug 23, 2024

Copy link
Copy Markdown
Author

@ChengJin01 Yes , rules include all floating point types, so doubles as well.

I've updated the code to handle all the 3 cases above for float & double.

@zl-wang

zl-wang commented Aug 23, 2024

Copy link
Copy Markdown
Contributor

@ChengJin01

As for case 3 struct { struct {float a; float b;} float c;}

you added float before c ... making it invalid declaration.

struct { struct {float a; float b;}} is an invalid type declaration as well ... you need a field name at least (I named it c previously in my case 3). but i understood you are referring to the same "type" as I ... it is 8-byte nested struct ALL_SP. since it has only one member ... so, it is not a complex. current code did it right?

@ChengJin01

ChengJin01 commented Aug 23, 2024

Copy link
Copy Markdown
Author

so, it is not a complex. current code did it right?

@zl-wang,

Yes, the latest changes already covers this case (a struct with a 8-byte nested struct ALL_SP) as that's my understanding of our clarification above.

@zl-wang zl-wang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can live with the position we come back to fix this corner case in the future. @TobiAjila what do you think?

Comment thread runtime/vm/LayoutFFITypeHelpers.hpp Outdated
@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch from 404d9fb to 99b9d25 Compare August 23, 2024 22:22
Comment thread runtime/vm/LayoutFFITypeHelpers.hpp Outdated
@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch 2 times, most recently from 8b12769 to 345c09f Compare August 24, 2024 00:31
@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch from 345c09f to 484dbc7 Compare August 24, 2024 00:57
Comment thread runtime/vm/LayoutFFITypeHelpers.hpp Outdated
Comment thread runtime/vm/LayoutFFITypeHelpers.hpp
@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch from 484dbc7 to 4704666 Compare August 26, 2024 15:21

@zl-wang zl-wang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i approved it on the basis that it catches the most likely cases (being good enough) and we are running out of time.

@ChengJin01

ChengJin01 commented Aug 26, 2024

Copy link
Copy Markdown
Author

@tajila, please double-check & approve it if no more concerns.

@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch 2 times, most recently from a7dd2c2 to e5c8489 Compare August 26, 2024 16:06
@ChengJin01

ChengJin01 commented Aug 26, 2024

Copy link
Copy Markdown
Author

Just fixed the code conflicts when rebasing the branch with the latest changes.

The changes resolve the issue with the register mapping for the
struct FF/DD or its variants in upcall on z/OS by categorizing
them into ALL_SP/ALL_DP placed on FPRs while other non-complex
type are categorized into AGGREGATE_OTHER placed on GPRs.

Fixes: eclipse-openj9#19952

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
@ChengJin01
ChengJin01 force-pushed the ffi_upcall_ff_dd_struct_fprs_zos branch from e5c8489 to babde24 Compare August 26, 2024 16:08
@tajila

tajila commented Aug 29, 2024

Copy link
Copy Markdown
Contributor

jenkins test sanity alinux64 jdk21

@tajila

tajila commented Aug 29, 2024

Copy link
Copy Markdown
Contributor

jenkins test sanity xlinux64 jdk22

@tajila

tajila commented Aug 29, 2024

Copy link
Copy Markdown
Contributor

jenkins test sanity xlinux jdk22

@ChengJin01

Copy link
Copy Markdown
Author

@dchopra001, please help confirm whether the fix works good in OpenJ9 FFI test suites.

@dchopra001

Copy link
Copy Markdown
Contributor

@dchopra001, please help confirm whether the fix works good in OpenJ9 FFI test suites.

This change fixes the issues we observed in openj9 functional tests.

We still see some failures in openjdk tests. I can't say with 100% certainty yet if they are all unrelated to this issue as I'm still working through them. However they don't look related so far.

@tajila

tajila commented Aug 29, 2024

Copy link
Copy Markdown
Contributor

jenkins test sanity zlinux jdk22

@ChengJin01

Copy link
Copy Markdown
Author

The test failures at https://openj9-jenkins.osuosl.org/job/Test_openjdk21_j9_sanity.functional_aarch64_linux_Personal/204/tapTestReport/ (jobs were not yet finished) had nothing to do with FFI related tests (passed).

@tajila
tajila merged commit 7efa776 into eclipse-openj9:master Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:vm os:zos project:panama Used to track Project Panama related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FFI Upcall: Recognizing certain unions as J9_FFI_UPCALL_SIG_TYPE_STRUCT_AGGREGATE_ALL_SP is inconsistent with z/OS ABI

6 participants