Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d055df

Browse files
authored
Merge pull request eclipse-openj9#14046 from pshipton/unicompressed0.29.1
(0.29.1) j9gc_createJavaLangString() must use Unicode length for Unicode strings
2 parents 9a13b0b + 7edde83 commit 7d055df

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

runtime/gc_base/StringTable.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
555555
bool translateSlashes = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_XLAT);
556556
bool anonClassName = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_ANON_CLASS_NAME);
557557
bool internString = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_INTERN);
558+
UDATA unicodeLength = 0;
558559

559560
Trc_MM_createJavaLangString_Entry(vmThread, length, data, stringFlags);
560561

@@ -568,13 +569,14 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
568569
/* Currently, the only users of isASCII when isUnicode is true are also gated by compressStrings, so
569570
* don't bother computing isASCII if compression is off.
570571
*/
572+
unicodeLength = length / 2;
571573
if (compressStrings) {
572574
U_16 *unicodeData = (U_16*)data;
573-
for (UDATA i = 0; i < length; ++i) {
575+
for (UDATA i = 0; i < unicodeLength; ++i) {
574576
if (unicodeData[i] > 0x7F) {
575577
isASCII = false;
576578
if (J2SE_VERSION(vm) >= J2SE_V17) {
577-
for (UDATA j = i; j < length; ++j) {
579+
for (UDATA j = i; j < unicodeLength; ++j) {
578580
if (unicodeData[j] > 0xFF) {
579581
isASCIIorLatin1 = false;
580582
break;
@@ -635,7 +637,6 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
635637
}
636638

637639
if (NULL == result) {
638-
UDATA unicodeLength = 0;
639640
UDATA allocateFlags = J9_ARE_ANY_BITS_SET(stringFlags, J9_STR_INSTRUMENTABLE)
640641
? J9_GC_ALLOCATE_OBJECT_INSTRUMENTABLE
641642
: J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE;
@@ -650,9 +651,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
650651
goto nomem;
651652
}
652653

653-
if (isUnicode) {
654-
unicodeLength = length / 2;
655-
} else {
654+
if (!isUnicode) {
656655
if (isASCII) {
657656
unicodeLength = length;
658657
} else {

0 commit comments

Comments
 (0)