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

Remove incorrect check in fast path indexOf code #19503

Merged
merged 1 commit into from
May 17, 2024

Conversation

IBMJimmyk
Copy link
Contributor

@IBMJimmyk IBMJimmyk commented May 15, 2024

For the recognized method JITHelpers.intrinsicIndexOfLatin1, the ch parameter is meant to be interpreted as an unsigned byte with a value of 0x00-0xFF. However, it gets passes into the method as a signed byte. This means for values 0x80-0xFF the data is sign extended inside of the register.

The fast path code generated by inlineIntrinsicIndexOf_P10 has a check the checks if the bits other than the lowest 8 bits are 0 and returns -1 early if this is the case. But, this check is wrong. It is possible to have a valid parameter where there upper bits are not 0 due to the sign extension.

This fix removes the check and instead zeros out the bits other than the lowest 8 bits. This is safe to do since it is known in advance that the byte data is meant to be interpreted as an unsigned byte and it is not possible to pass in an invalid value to this parameter. Also, this is needed since the byte parameter is eventually compared against a loaded byte that was zero extended.

Fixes #18974

For the recognized method JITHelpers.intrinsicIndexOfLatin1, the ch parameter
is meant to be interpreted as an unsigned byte with a value of 0x00-0xFF.
However, it gets passes into the method as a signed byte. This means for
values 0x80-0xFF the data is sign extended inside of the register.

The fast path code generated by inlineIntrinsicIndexOf_P10 has a check the
checks if the bits other than the lowest 8 bits are 0 and returns -1 early if
this is the case. But, this check is wrong. It is possible to have a valid
parameter where there upper bits are not 0 due to the sign extension.

This fix removes the check and instead zeros out the bits other than the
lowest 8 bits. This is safe to do since it is known in advance that the byte
data is meant to be interpreted as an unsigned byte and it is not possible to
pass in an invalid value to this parameter. Also, this is needed since the
byte parameter is eventually compared against a loaded byte that was zero
extended.

Signed-off-by: jimmyk <jimmyk@ca.ibm.com>
@IBMJimmyk IBMJimmyk changed the title [WIP] Remove incorrect check in fast path indexOf code Remove incorrect check in fast path indexOf code May 16, 2024
@IBMJimmyk
Copy link
Contributor Author

I tested my changes across a large variety of inputs to String.indexOf. I confirmed that before my fix I could reliably reproduce the error. After my fix the, errors were all gone.

Investigation into this problem initially started from this issue: #18974
It was also confirmed to no longer occur after the fix.

As a result, I have removed the WIP tag.

@zl-wang Could you take a look at this change and provide feedback on if anything needs to be changed?

Copy link
Contributor

@zl-wang zl-wang left a comment

Choose a reason for hiding this comment

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

LGTM

@zl-wang
Copy link
Contributor

zl-wang commented May 16, 2024

Jenkins test sanity.functional aix jdk8,jdk11,jdk17

@zl-wang
Copy link
Contributor

zl-wang commented May 16, 2024

plinux testing is skipped for the time being, due to UNB machine problem. jimmy personally tested plinux already.

@pshipton pshipton merged commit 64d4ef4 into eclipse-openj9:master May 17, 2024
9 checks passed
@pshipton
Copy link
Member

@IBMJimmyk pls create a PR against v0.44.0-release

@IBMJimmyk
Copy link
Contributor Author

I created the v0.44.0 PR here:
#19513

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.

jdk_nio_0_FAILED sun/nio/cs/TestStringCoding.java RuntimeException: getBytes(csn) failed -> x-IBM29626C
3 participants