Skip to content

Commit

Permalink
Merge pull request #18798 from keithc-ca/decompress43
Browse files Browse the repository at this point in the history
(0.43) Fix interpretation of compressed strings
  • Loading branch information
pshipton committed Jan 23, 2024
2 parents c082905 + b8d4c25 commit 220e78c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
14 changes: 6 additions & 8 deletions runtime/jcl/common/jclreflect.c
Expand Up @@ -28,12 +28,12 @@ compareJavaStringToPartialUTF8(J9VMThread * vmThread, j9object_t string, U_8 * u
{
UDATA unicodeLength = J9VMJAVALANGSTRING_LENGTH(vmThread, string);
j9object_t unicodeBytes = J9VMJAVALANGSTRING_VALUE(vmThread, string);
UDATA i;
UDATA i = 0;

if (IS_STRING_COMPRESSED(vmThread, string)) {
for (i = 0; i < unicodeLength; i++) {
U_16 utfChar;
U_32 count;
U_16 utfChar = 0;
U_32 count = 0;

/* If the String is longer than the UTF, then they don't match */

Expand All @@ -51,14 +51,14 @@ compareJavaStringToPartialUTF8(J9VMThread * vmThread, j9object_t string, U_8 * u
if (utfChar == '/') {
utfChar = '.';
}
if (utfChar != J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes, i)) {
if (utfChar != (U_8)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes, i)) {
return FALSE;
}
}
} else {
for (i = 0; i < unicodeLength; i++) {
U_16 utfChar;
U_32 count;
U_16 utfChar = 0;
U_32 count = 0;

/* If the String is longer than the UTF, then they don't match */

Expand All @@ -84,5 +84,3 @@ compareJavaStringToPartialUTF8(J9VMThread * vmThread, j9object_t string, U_8 * u

return TRUE;
}


9 changes: 5 additions & 4 deletions runtime/jvmti/jvmtiHeap.c
Expand Up @@ -1750,9 +1750,10 @@ static jvmtiIterationControl
wrap_stringPrimitiveCallback(J9JavaVM * vm, J9JVMTIHeapData * iteratorData)
{
jvmtiIterationControl rc = JVMTI_ITERATION_ABORT;
jlong tag;
jint stringLength, i;
jchar * stringValue;
jlong tag = 0;
jint stringLength = 0;
jint i = 0;
jchar * stringValue = NULL;
PORT_ACCESS_FROM_JAVAVM(vm);
j9object_t bytes = J9VMJAVALANGSTRING_VALUE(iteratorData->currentThread, iteratorData->object);
UDATA offset = 0;
Expand All @@ -1774,7 +1775,7 @@ wrap_stringPrimitiveCallback(J9JavaVM * vm, J9JVMTIHeapData * iteratorData)
/* Decompress the string byte at a time, this probably can't be
*/
for (i = 0; i < stringLength; i++) {
stringValue[i] = J9JAVAARRAYOFBYTE_LOAD(iteratorData->currentThread, bytes, offset);
stringValue[i] = (U_8)J9JAVAARRAYOFBYTE_LOAD(iteratorData->currentThread, bytes, offset);
offset++;
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/KeyHashTable.c
Expand Up @@ -125,7 +125,7 @@ classHashEqualFn(void *tableNode, void *queryNode, void *userData)
BOOLEAN isTableNodeHiddenClass = (TYPE_CLASS == tableNodeType)
&& (TAG_RAM_CLASS == (tableNodeTag & MASK_RAM_CLASS))
&& J9ROMCLASS_IS_HIDDEN(((KeyHashTableClassEntry*)tableNode)->ramClass->romClass);

if (isTableNodeHiddenClass) {
/* Hidden class is keyed on its rom address, not on its name. */
PORT_ACCESS_FROM_JAVAVM(javaVM);
Expand All @@ -149,7 +149,7 @@ classHashEqualFn(void *tableNode, void *queryNode, void *userData)
U_8 c = 0;

if (isCompressed) {
unicode = J9JAVAARRAYOFBYTE_LOAD_VM(javaVM, charArray, i);
unicode = (U_8)J9JAVAARRAYOFBYTE_LOAD_VM(javaVM, charArray, i);
} else {
unicode = J9JAVAARRAYOFCHAR_LOAD_VM(javaVM, charArray, i);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ classHashFn(void *key, void *userData)

if (IS_STRING_COMPRESSED_VM(javaVM, stringObject)) {
while (i < end) {
hash = (hash << 5) - hash + J9JAVAARRAYOFBYTE_LOAD_VM(javaVM, charArray, i);
hash = (hash << 5) - hash + (U_8)J9JAVAARRAYOFBYTE_LOAD_VM(javaVM, charArray, i);
++i;
}
} else {
Expand Down
12 changes: 6 additions & 6 deletions runtime/vm/stringhelpers.cpp
Expand Up @@ -75,8 +75,8 @@ compareCompressedUnicode(J9VMThread *vmThread, j9object_t unicodeBytes1, j9objec
if (unicodeBytes1 != unicodeBytes2) {
UDATA i = 0;
while (0 != length) {
U_16 unicodeChar1 = (U_16)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes1, i);
U_16 unicodeChar2 = (U_16)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes2, i);
U_16 unicodeChar1 = (U_8)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes1, i);
U_16 unicodeChar2 = (U_8)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes2, i);
if (unicodeChar1 != unicodeChar2) {
result = 0;
break;
Expand All @@ -103,7 +103,7 @@ compareCompressedUnicodeToUncompressedUnicode(J9VMThread *vmThread, j9object_t u
UDATA i = 0;
while (0 != length) {
U_16 unicodeChar1 = J9JAVAARRAYOFCHAR_LOAD(vmThread, unicodeBytes1, i);
U_16 unicodeChar2 = (U_16)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes2, i);
U_16 unicodeChar2 = (U_8)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes2, i);
if (unicodeChar1 != unicodeChar2) {
result = 0;
break;
Expand All @@ -129,7 +129,7 @@ compareStrings(J9VMThread *vmThread, j9object_t string1, j9object_t string2)
UDATA stringLength1 = J9VMJAVALANGSTRING_LENGTH(vmThread, string1);
UDATA stringLength2 = J9VMJAVALANGSTRING_LENGTH(vmThread, string2);

if (stringLength1 != stringLength2) {
if (stringLength1 != stringLength2) {
result = 0;
} else {
j9object_t unicodeBytes1 = J9VMJAVALANGSTRING_VALUE(vmThread, string1);
Expand Down Expand Up @@ -177,8 +177,8 @@ compareStringToUTF8(J9VMThread *vmThread, j9object_t string, UDATA translateDots

if (IS_STRING_COMPRESSED(vmThread, string)) {
while ((tmpUtfLength != 0) && (tmpStringLength != 0)) {
U_16 unicodeChar = (U_16)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes, i);
U_16 utfChar;
U_16 unicodeChar = (U_8)J9JAVAARRAYOFBYTE_LOAD(vmThread, unicodeBytes, i);
U_16 utfChar = 0;
UDATA consumed = decodeUTF8Char(tmpUtfData, &utfChar);

if (translateDots) {
Expand Down

0 comments on commit 220e78c

Please sign in to comment.