Skip to content

Commit

Permalink
j9gc_createJavaLangString() must use Unicode length for Unicode strings
Browse files Browse the repository at this point in the history
j9gc_createJavaLangString() must use the Unicode length when checking if
a Unicode string is ASCII or Latin 1.

Bug introduced by #11700 in
0.25 although there was a different but similar problem in previous
releases.

Issue #13655

Signed-off-by: Peter Shipton <[email protected]>
  • Loading branch information
pshipton committed Nov 30, 2021
1 parent 9a13b0b commit 7edde83
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions runtime/gc_base/StringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
bool translateSlashes = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_XLAT);
bool anonClassName = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_ANON_CLASS_NAME);
bool internString = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_INTERN);
UDATA unicodeLength = 0;

Trc_MM_createJavaLangString_Entry(vmThread, length, data, stringFlags);

Expand All @@ -568,13 +569,14 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
/* Currently, the only users of isASCII when isUnicode is true are also gated by compressStrings, so
* don't bother computing isASCII if compression is off.
*/
unicodeLength = length / 2;
if (compressStrings) {
U_16 *unicodeData = (U_16*)data;
for (UDATA i = 0; i < length; ++i) {
for (UDATA i = 0; i < unicodeLength; ++i) {
if (unicodeData[i] > 0x7F) {
isASCII = false;
if (J2SE_VERSION(vm) >= J2SE_V17) {
for (UDATA j = i; j < length; ++j) {
for (UDATA j = i; j < unicodeLength; ++j) {
if (unicodeData[j] > 0xFF) {
isASCIIorLatin1 = false;
break;
Expand Down Expand Up @@ -635,7 +637,6 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
}

if (NULL == result) {
UDATA unicodeLength = 0;
UDATA allocateFlags = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_INSTRUMENTABLE)
? J9_GC_ALLOCATE_OBJECT_INSTRUMENTABLE
: J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE;
Expand All @@ -650,9 +651,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
goto nomem;
}

if (isUnicode) {
unicodeLength = length / 2;
} else {
if (!isUnicode) {
if (isASCII) {
unicodeLength = length;
} else {
Expand Down

0 comments on commit 7edde83

Please sign in to comment.