Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of XPLINK call descriptor offset #4154

Merged
merged 3 commits into from
Jul 24, 2019

Conversation

fjeremic
Copy link
Contributor

The call descriptor offset in the NOP following a call within an XPLINK
frame was not being correctly calculated. The patch location was
correct, however the offset encoded was from the patch location, which
is incorrect.

As per the documentation linked in the source code the value we wish to
encoding is a (positive) signed offset in doublewords from the
doubleword at or preceding the return point (NOP) to the XPLINK call
descriptor for this signature.

This is not something we can encoding with the existing locations, and
due to the doubleword alignment that is required it is not something
that we should generalize either since we don't envision other uses for
such a strict API. Instead we create a private relocation in the XPLINK
linkage class and handle the relocation there.

Signed-off-by: Filip Jeremic fjeremic@ca.ibm.com

@fjeremic
Copy link
Contributor Author

fjeremic commented Jul 23, 2019

Although this change is in OMR I have only been able to produce this bug via OpenJ9 since OMR does not support calling non-XPLINK targets. I'm attaching the test case suite to this comment below. It adapts the JNI tests found in [1] as a standalone since we need to compile the said tests with non-XPLINK linkage.

In the ZIP file attached you may find both ASCII and EBCDIC logs of a sample of 4 method compilations which have different alignments modulo 8 for an exhaustive confirmation that the XPLINK offset descriptor is now encoded correctly. I'll copy/paste the relevant snippets here for the reviewer's convenience:

nopLocationIs0Modulo8.trace.ascii:

0x495BBF96 00000096 [0x49922720] 0d 76                      BASR    GPR7,GPR6       # Call "JniArgTests.nativeIZrZ(I[Z)Z"
0x495BBF98 00000098 [0x49922AA0]                            Label L0016:
0x495BBF98 00000098 [0x49922F50]                            ASSOCREGS
0x495BBF98 00000098 [0x49922C40] 47 00 00 1a                DC      0x47000000
...
0x495BC068 00000168                                         Snippet Label L0023:    ; Constant Data Snippet
0x495BC068 00000168              00 00 00 00 01 00 00 00    DC    0x0000000000000000

nopLocationIs2Modulo8.trace.ascii:

0x495C23A0 000000a0 [0x499227E0] 0d 76                      BASR    GPR7,GPR6       # Call "JniArgTests.nativeJBrB(JB)B"
0x495C23A2 000000a2 [0x49922B60]                            Label L0016:
0x495C23A2 000000a2 [0x49923010]                            ASSOCREGS
0x495C23A2 000000a2 [0x49922D00] 47 00 00 19                DC      0x47000000
...
0x495C2468 00000168                                         Snippet Label L0021:    ; Constant Data Snippet
0x495C2468 00000168              00 00 00 00 01 00 00 00    DC    0x0000000000000000

nopLocationIs4Modulo8.trace.ascii:

0x495BDB8A 0000008a [0x499224F0] 0d 76                      BASR    GPR7,GPR6       # Call "JniArgTests.nativeBBrB(BB)B"
0x495BDB8C 0000008c [0x49922870]                            Label L0016:
0x495BDB8C 0000008c [0x49922D20]                            ASSOCREGS
0x495BDB8C 0000008c [0x49922A10] 47 00 00 1a                DC      0x47000000
...
0x495BDC58 00000158                                         Snippet Label L0021:    ; Constant Data Snippet
0x495BDC58 00000158              00 00 00 00 01 00 00 00    DC    0x0000000000000000

nopLocationIs6Modulo8.trace.ascii (note the float parameter descriptor is properly encoded):

0x495BEB84 00000084 [0x499225E0] 0d 76                      BASR    GPR7,GPR6       # Call "JniArgTests.nativeBFrB(BF)B"
0x495BEB86 00000086 [0x49922960]                            Label L0016:
0x495BEB86 00000086 [0x49922E10]                            ASSOCREGS
0x495BEB86 00000086 [0x49922B00] 47 00 00 1a                DC      0x47000000
...
0x495BEC50 00000150                                         Snippet Label L0021:    ; Constant Data Snippet
0x495BEC50 00000150              00 00 00 00 01 4c 00 00    DC    0x0000000000000000

[1] https://github.com/eclipse/openj9/tree/master/runtime/tests/jniarg

NonXPLINKTest.zip

@fjeremic
Copy link
Contributor Author

@joransiu @sehirst could you please review?

@genie-omr build zlinux,zos

Copy link
Contributor

@joransiu joransiu left a comment

Choose a reason for hiding this comment

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

In the 3rd paragraph of the commit message: "This is not something we can encoding with the existing locations" -> "existing relocations"?

compiler/z/codegen/snippet/XPLINKCallDescriptorSnippet.cpp Outdated Show resolved Hide resolved
The call descriptor offset in the NOP following a call within an XPLINK
frame was not being correctly calculated. The patch location was
correct, however the offset encoded was from the patch location, which
is incorrect.

As per the documentation linked in the source code the value we wish to
encoding is a (positive) signed offset in doublewords from  the
doubleword at or preceding the return point (NOP) to the XPLINK call
descriptor for this signature.

This is not something we can encode with the existing relocations, and
due to the doubleword alignment that is required it is not something
that we should generalize either since we don't envision other uses for
such a strict API. Instead we create a private relocation in the XPLINK
linkage class and handle the relocation there.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
…location failsafe

Fail the compilation if we are unable to encode the distance to the XPLINKCallDescriptorSnippet.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
Copy link
Contributor

@joransiu joransiu left a comment

Choose a reason for hiding this comment

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

Good idea inheriting from ConstantDataSnippet. The changes LGTM. Thanks!

@fjeremic
Copy link
Contributor Author

@genie-omr build zlinux,zos

Use the already calculated offsetToCallDescriptor instead of
recalculating it again.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
@fjeremic
Copy link
Contributor Author

@sehirst noted a small optimization which I've delivered as part of 6c0ad4f.

@genie-omr build zlinux,zos

Copy link
Contributor

@sehirst sehirst left a comment

Choose a reason for hiding this comment

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

looks good to me

compiler/z/codegen/SystemLinkagezOS.cpp Outdated Show resolved Hide resolved
@mstoodle mstoodle self-assigned this Jul 24, 2019
@mstoodle
Copy link
Contributor

Commits well structured, only affects compiler on Z platform so Z testing is sufficient, code has been reviewed by two developers with Z background. Since @fjeremic can't merge it himself, I'll do it. Thanks, everyone!

@mstoodle mstoodle merged commit cb2479c into eclipse:master Jul 24, 2019
fjeremic added a commit to fjeremic/openj9 that referenced this pull request Sep 10, 2019
The fatal bug fixed in eclipse/omr#4154 was not caught during
automated testing because there currently do not exist JNI tests
which are built with non-XPLINK (system) linkage. To prevent such
obvious bugs from escaping into production we reuse the jniargtests
and compile them with system linkage on z/OS 31-bit.

We modify the existing Java test so it can run against custom native
libraries, then we build two native libraries on z/OS, one with
XPLINK which is already done today, and one with system linkage which
will exercise callouts to non-XPLINK natives.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants