Skip to content

[Backport] [Oracle GraalVM] [GR-71539] Backport to 23.1: TruffleStrings: fix incorrect offset handling in FromJavaStringNode.#274

Open
bulasevich wants to merge 1 commit intograalvm:masterfrom
bulasevich:GR-71539
Open

[Backport] [Oracle GraalVM] [GR-71539] Backport to 23.1: TruffleStrings: fix incorrect offset handling in FromJavaStringNode.#274
bulasevich wants to merge 1 commit intograalvm:masterfrom
bulasevich:GR-71539

Conversation

@bulasevich
Copy link
Copy Markdown
Collaborator

@bulasevich bulasevich commented Apr 8, 2026

This PR backports:

Conflicts:

change: moves IF condition under length1Profile.profile call
issue: mainline IF condition uses TStringOps.readFromByteArrayS1 introduced by 0b835c83 TruffleStrings: internal refactor
resolution: use the old IF condition, but move it under the length1Profile.profile call

<<<<<<< HEAD
                if (length == 1 && TStringOps.readFromByteArray(arrayJS, 1, charOffset) <= 0xff) {
                    return TStringConstants.getSingleByte(Encoding.UTF_16, TStringOps.readFromByteArray(arrayJS, 1, charOffset));
=======
                if (length1Profile.profile(node, length == 1 && TStringOps.readFromByteArrayS1(arrayJS, charOffset) <= 0xff)) {
                    return TStringConstants.getSingleByte(Encoding.UTF_16, TStringOps.readFromByteArrayS1(arrayJS, charOffset));
>>>>>>> 9b57a1aa02f (TruffleStrings: fix incorrect offset handling in FromJavaStringNode)

change: modifies the String hash calculation passed as a parameter to createFromByteArray
issue: not applicable without 4dc61ab9 Preserve already computed hash code in Java String to TruffleString conversion.
resolution: skipped

<<<<<<< HEAD
            TruffleString ret = TruffleString.createFromArray(array, offset, length, stride, Encoding.UTF_16, codePointLength, codeRange);
            if (length == javaString.length()) {
                assert charOffset == 0;
                TruffleString wrapped = TruffleString.createWrapJavaString(javaString, codePointLength, codeRange);
                ret.cacheInsertFirstBeforePublished(wrapped);
            }
            return ret;
=======
            int hash = fullLength ? TStringUnsafe.getJavaStringHashMasked(javaString) : 0;
            return TruffleString.createFromByteArray(array, offset, length, stride, Encoding.UTF_16, codePointLength, codeRange, hash, true);
>>>>>>> 9b57a1aa02f (TruffleStrings: fix incorrect offset handling in FromJavaStringNode)

Closes: #257

Test TStringFromJavaStringTest passed.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 8, 2026
(cherry picked from commit 9b57a1aa02fece51257465637e38ebced0ab7bc7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backport] [Oracle GraalVM] [GR-71539] Backport to 23.1: TruffleStrings: fix incorrect offset handling in FromJavaStringNode.

2 participants