@@ -555,6 +555,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
555
555
bool translateSlashes = J9_ARE_ANY_BITS_SET (stringFlags, J9_STR_XLAT);
556
556
bool anonClassName = J9_ARE_ANY_BITS_SET (stringFlags, J9_STR_ANON_CLASS_NAME);
557
557
bool internString = J9_ARE_ANY_BITS_SET (stringFlags, J9_STR_INTERN);
558
+ UDATA unicodeLength = 0 ;
558
559
559
560
Trc_MM_createJavaLangString_Entry (vmThread, length, data, stringFlags);
560
561
@@ -568,13 +569,14 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
568
569
/* Currently, the only users of isASCII when isUnicode is true are also gated by compressStrings, so
569
570
* don't bother computing isASCII if compression is off.
570
571
*/
572
+ unicodeLength = length / 2 ;
571
573
if (compressStrings) {
572
574
U_16 *unicodeData = (U_16*)data;
573
- for (UDATA i = 0 ; i < length ; ++i) {
575
+ for (UDATA i = 0 ; i < unicodeLength ; ++i) {
574
576
if (unicodeData[i] > 0x7F ) {
575
577
isASCII = false ;
576
578
if (J2SE_VERSION (vm) >= J2SE_V17) {
577
- for (UDATA j = i; j < length ; ++j) {
579
+ for (UDATA j = i; j < unicodeLength ; ++j) {
578
580
if (unicodeData[j] > 0xFF ) {
579
581
isASCIIorLatin1 = false ;
580
582
break ;
@@ -635,7 +637,6 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
635
637
}
636
638
637
639
if (NULL == result) {
638
- UDATA unicodeLength = 0 ;
639
640
UDATA allocateFlags = J9_ARE_ANY_BITS_SET (stringFlags, J9_STR_INSTRUMENTABLE)
640
641
? J9_GC_ALLOCATE_OBJECT_INSTRUMENTABLE
641
642
: J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE;
@@ -650,9 +651,7 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s
650
651
goto nomem;
651
652
}
652
653
653
- if (isUnicode) {
654
- unicodeLength = length / 2 ;
655
- } else {
654
+ if (!isUnicode) {
656
655
if (isASCII) {
657
656
unicodeLength = length;
658
657
} else {
0 commit comments