Skip to content
This repository has been archived by the owner. It is now read-only.

8260927: StringBuilder::insert is incorrect without Compact Strings #143

Closed

Conversation

@shipilev
Copy link
Contributor

@shipilev shipilev commented Feb 2, 2021

Discovered it with ARM32 tier1 tests, which runs with -CompactStrings by default. But the bug is actually generic:

$ CONF=linux-x86_64-server-fastdebug make run-test TEST=java/lang/StringBuilder/Insert.java TEST_VM_OPTS="-XX:-CompactStrings"

test Insert.insertOffset(): failure
java.lang.AssertionError: expected [??abc] but found [efabc]
	at org.testng.Assert.fail(Assert.java:94)
	at org.testng.Assert.failNotEquals(Assert.java:496)
	at org.testng.Assert.assertEquals(Assert.java:125)
	at org.testng.Assert.assertEquals(Assert.java:178)
	at org.testng.Assert.assertEquals(Assert.java:188)
	at Insert.insertOffset(Insert.java:45)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

I believe this is a regression from JDK-8254082.

    void getBytes(byte[] dst, int srcPos, int dstBegin, byte coder, int length) {
        if (coder() == coder) {
            System.arraycopy(value, srcPos, dst, dstBegin << coder, length << coder());
        } else {    // this.coder == LATIN && coder == UTF16
            StringLatin1.inflate(value, srcPos, dst, dstBegin, length);
        }
    }

When coder is UTF16 (which it guaranteed to be without CompactStrings), then srcPos in byte[] array has to be adjusted by coder as well.

Additional testing:

  • Linux ARM32, affected test now passes
  • Linux x86_64, affected test now passes
  • Linux x86_64 tier1 default, passes
  • Linux x86_64 tier1, -XX:-CompactStrings, passes modulo two testbugs (JDK-8260933, JDK-8260934)
  • Linux x86_64 tier2 default, passes
  • Linux x86_64 tier2, -XX:-CompactStrings, passes

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8260927: StringBuilder::insert is incorrect without Compact Strings

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk16 pull/143/head:pull/143
$ git checkout pull/143

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Feb 2, 2021

👋 Welcome back shade! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

@openjdk openjdk bot commented Feb 2, 2021

@shipilev The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs label Feb 2, 2021
@shipilev shipilev marked this pull request as ready for review Feb 2, 2021
@openjdk openjdk bot added the rfr label Feb 2, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Feb 2, 2021

Webrevs

cl4es
cl4es approved these changes Feb 2, 2021
Copy link
Member

@cl4es cl4es left a comment

Looks good, thanks for fixing this.

Should we add an explicit run with -CompactStrings to the Insert.java test? That'd have caught this issue sooner - perhaps already by the GA testing.

@openjdk
Copy link

@openjdk openjdk bot commented Feb 2, 2021

@shipilev This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8260927: StringBuilder::insert is incorrect without Compact Strings

Reviewed-by: redestad, alanb, rriggs, jlaskey

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Feb 2, 2021
@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Feb 2, 2021

Should we add an explicit run with -CompactStrings to the Insert.java test? That'd have caught this issue sooner - perhaps already by the GA testing.

Yes, I thought about the same. Added and re-checked that it catches the failure. (I also added -XX:-CompactStrings jobs to my CI workflows).

cl4es
cl4es approved these changes Feb 2, 2021
Copy link
Member

@cl4es cl4es left a comment

Good

@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Feb 2, 2021

Thanks. GHA are green, tier1, tier2 are clean, JDK 16 fix approval is there. I think it checks all the boxes.

/integrate

@openjdk openjdk bot closed this Feb 2, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Feb 2, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Feb 2, 2021

@shipilev Pushed as commit 081fa3e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants